I18N - color.cpp

- Localized color.cpp, fingers ache.
- Made a couple of parse.cpp functions non-static.
This commit is contained in:
Paul Beckingham 2009-06-06 23:31:04 -04:00
parent db52cf7327
commit 7965bd5b4f
6 changed files with 155 additions and 121 deletions

View file

@ -142,6 +142,8 @@
548 on_bright_magenta
549 on_bright_cyan
550 on_bright_white
551 off
552 Unknown color name
# 6xx Config

View file

@ -238,8 +238,8 @@ void Context::parse ()
foreach (arg, args)
{
// Ignore any argument that is "rc:...", because that is the command line
// specified rc file.
// Skip any argument that starts with "rc:" or "rc." because it has already
// been processed.
if (arg->substr (0, 3) != "rc:" ||
arg->substr (0, 3) != "rc.")
{
@ -251,12 +251,23 @@ void Context::parse ()
std::string to;
bool global;
std::vector <int> sequence;
*/
// The '--' argument shuts off all parsing - everything is an argument.
if (arg == "--")
if (*arg == "--")
terminated = true;
// An id is the first argument found that contains all digits.
// Sequence
// Note: "add" doesn't require an ID
else if (command != "add" &&
validSequence (*arg, sequence) &&
! foundSomethingAfterSequence)
{
std::cout << "# found sequence" << std::endl;
foundSequence = true;
}
/*
else if (lowerCase (command) != "add" && // "add" doesn't require an ID
validSequence (arg, sequence) &&
! foundSomethingAfterSequence)
@ -265,7 +276,9 @@ void Context::parse ()
foreach (id, sequence)
task.addId (*id);
}
*/
/*
// Tags begin with + or - and contain arbitrary text.
else if (validTag (arg))
{
@ -303,7 +316,9 @@ void Context::parse ()
descCandidate += arg;
}
}
*/
/*
// Substitution of description text.
else if (validSubstitution (arg, from, to, global))
{
@ -345,22 +360,18 @@ void Context::parse ()
// terminated, therefore everything subsequently is a description.
else
{
/*
if (foundSequence)
foundSomethingAfterSequence = true;
if (descCandidate.length ())
descCandidate += " ";
descCandidate += arg;
*/
descCandidate += *arg;
}
}
}
/*
if (validDescription (descCandidate))
task.set ("description", descCandidate);
*/
// TODO Replace parse.cpp:parse
throw std::string ("unimplemented Context::parse");

View file

@ -25,8 +25,12 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <string>
#include "Context.h"
#include "i18n.h"
#include "color.h"
extern Context context;
////////////////////////////////////////////////////////////////////////////////
namespace Text
{
@ -36,67 +40,67 @@ std::string colorName (color c)
switch (c)
{
case nocolor: return "";
case off: return "off";
case off: return context.stringtable.get (COLOR_OFF, "off");
case bold: return "bold";
case underline: return "underline";
case bold_underline: return "bold_underline";
case bold: return context.stringtable.get (COLOR_BOLD, "bold");
case underline: return context.stringtable.get (COLOR_UL, "underline");
case bold_underline: return context.stringtable.get (COLOR_B_UL, "bold_underline");
case black: return "black";
case red: return "red";
case green: return "green";
case yellow: return "yellow";
case blue: return "blue";
case magenta: return "magenta";
case cyan: return "cyan";
case white: return "white";
case black: return context.stringtable.get (COLOR_BLACK, "black");
case red: return context.stringtable.get (COLOR_RED, "red");
case green: return context.stringtable.get (COLOR_GREEN, "green");
case yellow: return context.stringtable.get (COLOR_YELLOW, "yellow");
case blue: return context.stringtable.get (COLOR_BLUE, "blue");
case magenta: return context.stringtable.get (COLOR_MAGENTA, "magenta");
case cyan: return context.stringtable.get (COLOR_CYAN, "cyan");
case white: return context.stringtable.get (COLOR_WHITE, "white");
case bold_black: return "bold_black";
case bold_red: return "bold_red";
case bold_green: return "bold_green";
case bold_yellow: return "bold_yellow";
case bold_blue: return "bold_blue";
case bold_magenta: return "bold_magenta";
case bold_cyan: return "bold_cyan";
case bold_white: return "bold_white";
case bold_black: return context.stringtable.get (COLOR_B_BLACK, "bold_black");
case bold_red: return context.stringtable.get (COLOR_B_RED, "bold_red");
case bold_green: return context.stringtable.get (COLOR_B_GREEN, "bold_green");
case bold_yellow: return context.stringtable.get (COLOR_B_YELLOW, "bold_yellow");
case bold_blue: return context.stringtable.get (COLOR_B_BLUE, "bold_blue");
case bold_magenta: return context.stringtable.get (COLOR_B_MAGENTA, "bold_magenta");
case bold_cyan: return context.stringtable.get (COLOR_B_CYAN, "bold_cyan");
case bold_white: return context.stringtable.get (COLOR_B_WHITE, "bold_white");
case underline_black: return "underline_black";
case underline_red: return "underline_red";
case underline_green: return "underline_green";
case underline_yellow: return "underline_yellow";
case underline_blue: return "underline_blue";
case underline_magenta: return "underline_magenta";
case underline_cyan: return "underline_cyan";
case underline_white: return "underline_white";
case underline_black: return context.stringtable.get (COLOR_UL_BLACK, "underline_black");
case underline_red: return context.stringtable.get (COLOR_UL_RED, "underline_red");
case underline_green: return context.stringtable.get (COLOR_UL_GREEN, "underline_green");
case underline_yellow: return context.stringtable.get (COLOR_UL_YELLOW, "underline_yellow");
case underline_blue: return context.stringtable.get (COLOR_UL_BLUE, "underline_blue");
case underline_magenta: return context.stringtable.get (COLOR_UL_MAGENTA, "underline_magenta");
case underline_cyan: return context.stringtable.get (COLOR_UL_CYAN, "underline_cyan");
case underline_white: return context.stringtable.get (COLOR_UL_WHITE, "underline_white");
case bold_underline_black: return "bold_underline_black";
case bold_underline_red: return "bold_underline_red";
case bold_underline_green: return "bold_underline_green";
case bold_underline_yellow: return "bold_underline_yellow";
case bold_underline_blue: return "bold_underline_blue";
case bold_underline_magenta: return "bold_underline_magenta";
case bold_underline_cyan: return "bold_underline_cyan";
case bold_underline_white: return "bold_underline_white";
case bold_underline_black: return context.stringtable.get (COLOR_B_UL_BLACK, "bold_underline_black");
case bold_underline_red: return context.stringtable.get (COLOR_B_UL_RED, "bold_underline_red");
case bold_underline_green: return context.stringtable.get (COLOR_B_UL_GREEN, "bold_underline_green");
case bold_underline_yellow: return context.stringtable.get (COLOR_B_UL_YELLOW, "bold_underline_yellow");
case bold_underline_blue: return context.stringtable.get (COLOR_B_UL_BLUE, "bold_underline_blue");
case bold_underline_magenta: return context.stringtable.get (COLOR_B_UL_MAGENTA, "bold_underline_magenta");
case bold_underline_cyan: return context.stringtable.get (COLOR_B_UL_CYAN, "bold_underline_cyan");
case bold_underline_white: return context.stringtable.get (COLOR_B_UL_WHITE, "bold_underline_white");
case on_black: return "on_black";
case on_red: return "on_red";
case on_green: return "on_green";
case on_yellow: return "on_yellow";
case on_blue: return "on_blue";
case on_magenta: return "on_magenta";
case on_cyan: return "on_cyan";
case on_white: return "on_white";
case on_black: return context.stringtable.get (COLOR_ON_BLACK, "on_black");
case on_red: return context.stringtable.get (COLOR_ON_RED, "on_red");
case on_green: return context.stringtable.get (COLOR_ON_GREEN, "on_green");
case on_yellow: return context.stringtable.get (COLOR_ON_YELLOW, "on_yellow");
case on_blue: return context.stringtable.get (COLOR_ON_BLUE, "on_blue");
case on_magenta: return context.stringtable.get (COLOR_ON_MAGENTA, "on_magenta");
case on_cyan: return context.stringtable.get (COLOR_ON_CYAN, "on_cyan");
case on_white: return context.stringtable.get (COLOR_ON_WHITE, "on_white");
case on_bright_black: return "on_bright_black";
case on_bright_red: return "on_bright_red";
case on_bright_green: return "on_bright_green";
case on_bright_yellow: return "on_bright_yellow";
case on_bright_blue: return "on_bright_blue";
case on_bright_magenta: return "on_bright_magenta";
case on_bright_cyan: return "on_bright_cyan";
case on_bright_white: return "on_bright_white";
case on_bright_black: return context.stringtable.get (COLOR_ON_BRIGHT_BLACK, "on_bright_black");
case on_bright_red: return context.stringtable.get (COLOR_ON_BRIGHT_RED, "on_bright_red");
case on_bright_green: return context.stringtable.get (COLOR_ON_BRIGHT_GREEN, "on_bright_green");
case on_bright_yellow: return context.stringtable.get (COLOR_ON_BRIGHT_YELLOW, "on_bright_yellow");
case on_bright_blue: return context.stringtable.get (COLOR_ON_BRIGHT_BLUE, "on_bright_blue");
case on_bright_magenta: return context.stringtable.get (COLOR_ON_BRIGHT_MAGENTA, "on_bright_magenta");
case on_bright_cyan: return context.stringtable.get (COLOR_ON_BRIGHT_CYAN, "on_bright_cyan");
case on_bright_white: return context.stringtable.get (COLOR_ON_BRIGHT_WHITE, "on_bright_white");
default: throw "Unknown Text::color value";
default: throw context.stringtable.get (COLOR_UNKNOWN, "Unknown color value");
}
return "";
@ -105,64 +109,64 @@ std::string colorName (color c)
////////////////////////////////////////////////////////////////////////////////
color colorCode (const std::string& c)
{
if (c == "off") return off;
else if (c == "bold") return bold;
else if (c == "underline") return underline;
else if (c == "bold_underline") return bold_underline;
if (c == context.stringtable.get (COLOR_OFF, "off")) return off;
else if (c == context.stringtable.get (COLOR_BOLD, "bold")) return bold;
else if (c == context.stringtable.get (COLOR_UL, "underline")) return underline;
else if (c == context.stringtable.get (COLOR_B_UL, "bold_underline")) return bold_underline;
else if (c == "black") return black;
else if (c == "red") return red;
else if (c == "green") return green;
else if (c == "yellow") return yellow;
else if (c == "blue") return blue;
else if (c == "magenta") return magenta;
else if (c == "cyan") return cyan;
else if (c == "white") return white;
else if (c == context.stringtable.get (COLOR_BLACK, "black")) return black;
else if (c == context.stringtable.get (COLOR_RED, "red")) return red;
else if (c == context.stringtable.get (COLOR_GREEN, "green")) return green;
else if (c == context.stringtable.get (COLOR_YELLOW, "yellow")) return yellow;
else if (c == context.stringtable.get (COLOR_BLUE, "blue")) return blue;
else if (c == context.stringtable.get (COLOR_MAGENTA, "magenta")) return magenta;
else if (c == context.stringtable.get (COLOR_CYAN, "cyan")) return cyan;
else if (c == context.stringtable.get (COLOR_WHITE, "white")) return white;
else if (c == "bold_black") return bold_black;
else if (c == "bold_red") return bold_red;
else if (c == "bold_green") return bold_green;
else if (c == "bold_yellow") return bold_yellow;
else if (c == "bold_blue") return bold_blue;
else if (c == "bold_magenta") return bold_magenta;
else if (c == "bold_cyan") return bold_cyan;
else if (c == "bold_white") return bold_white;
else if (c == context.stringtable.get (COLOR_B_BLACK, "bold_black")) return bold_black;
else if (c == context.stringtable.get (COLOR_B_RED, "bold_red")) return bold_red;
else if (c == context.stringtable.get (COLOR_B_GREEN, "bold_green")) return bold_green;
else if (c == context.stringtable.get (COLOR_B_YELLOW, "bold_yellow")) return bold_yellow;
else if (c == context.stringtable.get (COLOR_B_BLUE, "bold_blue")) return bold_blue;
else if (c == context.stringtable.get (COLOR_B_MAGENTA, "bold_magenta")) return bold_magenta;
else if (c == context.stringtable.get (COLOR_B_CYAN, "bold_cyan")) return bold_cyan;
else if (c == context.stringtable.get (COLOR_B_WHITE, "bold_white")) return bold_white;
else if (c == "underline_black") return underline_black;
else if (c == "underline_red") return underline_red;
else if (c == "underline_green") return underline_green;
else if (c == "underline_yellow") return underline_yellow;
else if (c == "underline_blue") return underline_blue;
else if (c == "underline_magenta") return underline_magenta;
else if (c == "underline_cyan") return underline_cyan;
else if (c == "underline_white") return underline_white;
else if (c == context.stringtable.get (COLOR_UL_BLACK, "underline_black")) return underline_black;
else if (c == context.stringtable.get (COLOR_UL_RED, "underline_red")) return underline_red;
else if (c == context.stringtable.get (COLOR_UL_GREEN, "underline_green")) return underline_green;
else if (c == context.stringtable.get (COLOR_UL_YELLOW, "underline_yellow")) return underline_yellow;
else if (c == context.stringtable.get (COLOR_UL_BLUE, "underline_blue")) return underline_blue;
else if (c == context.stringtable.get (COLOR_UL_MAGENTA, "underline_magenta")) return underline_magenta;
else if (c == context.stringtable.get (COLOR_UL_CYAN, "underline_cyan")) return underline_cyan;
else if (c == context.stringtable.get (COLOR_UL_WHITE, "underline_white")) return underline_white;
else if (c == "bold_underline_black") return bold_underline_black;
else if (c == "bold_underline_red") return bold_underline_red;
else if (c == "bold_underline_green") return bold_underline_green;
else if (c == "bold_underline_yellow") return bold_underline_yellow;
else if (c == "bold_underline_blue") return bold_underline_blue;
else if (c == "bold_underline_magenta") return bold_underline_magenta;
else if (c == "bold_underline_cyan") return bold_underline_cyan;
else if (c == "bold_underline_white") return bold_underline_white;
else if (c == context.stringtable.get (COLOR_B_UL_BLACK, "bold_underline_black")) return bold_underline_black;
else if (c == context.stringtable.get (COLOR_B_UL_RED, "bold_underline_red")) return bold_underline_red;
else if (c == context.stringtable.get (COLOR_B_UL_GREEN, "bold_underline_green")) return bold_underline_green;
else if (c == context.stringtable.get (COLOR_B_UL_YELLOW, "bold_underline_yellow")) return bold_underline_yellow;
else if (c == context.stringtable.get (COLOR_B_UL_BLUE, "bold_underline_blue")) return bold_underline_blue;
else if (c == context.stringtable.get (COLOR_B_UL_MAGENTA, "bold_underline_magenta")) return bold_underline_magenta;
else if (c == context.stringtable.get (COLOR_B_UL_CYAN, "bold_underline_cyan")) return bold_underline_cyan;
else if (c == context.stringtable.get (COLOR_B_UL_WHITE, "bold_underline_white")) return bold_underline_white;
else if (c == "on_black") return on_black;
else if (c == "on_red") return on_red;
else if (c == "on_green") return on_green;
else if (c == "on_yellow") return on_yellow;
else if (c == "on_blue") return on_blue;
else if (c == "on_magenta") return on_magenta;
else if (c == "on_cyan") return on_cyan;
else if (c == "on_white") return on_white;
else if (c == context.stringtable.get (COLOR_ON_BLACK, "on_black")) return on_black;
else if (c == context.stringtable.get (COLOR_ON_RED, "on_red")) return on_red;
else if (c == context.stringtable.get (COLOR_ON_GREEN, "on_green")) return on_green;
else if (c == context.stringtable.get (COLOR_ON_YELLOW, "on_yellow")) return on_yellow;
else if (c == context.stringtable.get (COLOR_ON_BLUE, "on_blue")) return on_blue;
else if (c == context.stringtable.get (COLOR_ON_MAGENTA, "on_magenta")) return on_magenta;
else if (c == context.stringtable.get (COLOR_ON_CYAN, "on_cyan")) return on_cyan;
else if (c == context.stringtable.get (COLOR_ON_WHITE, "on_white")) return on_white;
else if (c == "on_bright_black") return on_bright_black;
else if (c == "on_bright_red") return on_bright_red;
else if (c == "on_bright_green") return on_bright_green;
else if (c == "on_bright_yellow") return on_bright_yellow;
else if (c == "on_bright_blue") return on_bright_blue;
else if (c == "on_bright_magenta") return on_bright_magenta;
else if (c == "on_bright_cyan") return on_bright_cyan;
else if (c == "on_bright_white") return on_bright_white;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_BLACK, "on_bright_black")) return on_bright_black;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_RED, "on_bright_red")) return on_bright_red;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_GREEN, "on_bright_green")) return on_bright_green;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_YELLOW, "on_bright_yellow")) return on_bright_yellow;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_BLUE, "on_bright_blue")) return on_bright_blue;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_MAGENTA, "on_bright_magenta")) return on_bright_magenta;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_CYAN, "on_bright_cyan")) return on_bright_cyan;
else if (c == context.stringtable.get (COLOR_ON_BRIGHT_WHITE, "on_bright_white")) return on_bright_white;
return nocolor;
}
@ -233,7 +237,7 @@ std::string decode (color c)
case on_bright_cyan: return "\033[106m";
case on_bright_white: return "\033[107m";
default: throw "Unknown Text::color value";
default: throw context.stringtable.get (COLOR_UNKNOWN, "Unknown color value");
}
return "";

View file

@ -164,6 +164,8 @@
#define COLOR_ON_BRIGHT_MAGENTA 548
#define COLOR_ON_BRIGHT_CYAN 549
#define COLOR_ON_BRIGHT_WHITE 550
#define COLOR_OFF 551
#define COLOR_UNKNOWN 552
// 6xx Config

View file

@ -302,6 +302,18 @@ static bool validId (const std::string& input)
////////////////////////////////////////////////////////////////////////////////
// 1,2-4,6
bool validSequence (
const std::string& input,
Sequence& sequence)
{
bool valid = true;
try { sequence.parse (input); }
catch (...) { valid = false; }
return valid;
}
static bool validSequence (
const std::string& input,
std::vector <int>& ids)
@ -363,14 +375,15 @@ static bool validTag (const std::string& input)
}
////////////////////////////////////////////////////////////////////////////////
static bool validDescription (const std::string& input)
bool validDescription (const std::string& input)
{
if (input.length () == 0) return false;
if (input.find ("\r") != std::string::npos) return false;
if (input.find ("\f") != std::string::npos) return false;
if (input.find ("\n") != std::string::npos) return false;
if (input.length () &&
input.find ("\r") == std::string::npos &&
input.find ("\f") == std::string::npos &&
input.find ("\n") == std::string::npos)
return true;
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -42,6 +42,8 @@ void parse (std::vector <std::string>&, std::string&, T&);
bool validPriority (const std::string&);
bool validDate (std::string&);
bool validDuration (std::string&);
bool validDescription (const std::string&);
bool validSequence (const std::string&, Sequence&);
void loadCustomReports ();
bool isCustomReport (const std::string&);
void allCustomReports (std::vector <std::string>&);