mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-24 08:56:43 +02:00
I18N
- One does not simply std::string::substr a UTF8 string, like a bloody caveman. Implemented utf8_substr, and added unit tests.
This commit is contained in:
parent
ae58b85339
commit
01e589a172
9 changed files with 108 additions and 16 deletions
|
@ -113,7 +113,9 @@ std::string Config::_defaults =
|
|||
"dateformat.info=m/d/Y H:N:S # Preferred display date format for information\n"
|
||||
"dateformat.report=m/d/Y # Preferred display date format for reports\n"
|
||||
"dateformat.annotation=m/d/Y # Preferred display date format for annotations\n"
|
||||
"weekstart=Sunday # Sunday or Monday only\n"
|
||||
"weekstart="
|
||||
STRING_DATE_SUNDAY_LONG
|
||||
" # Sunday or Monday only\n"
|
||||
"displayweeknumber=yes # Show week numbers on calendar\n"
|
||||
"due=7 # Task is considered due in 7 days\n"
|
||||
"\n"
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <i18n.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
#include <utf8.h>
|
||||
#include <main.h>
|
||||
#include <CmdCalendar.h>
|
||||
|
||||
|
@ -429,24 +430,24 @@ std::string CmdCalendar::renderMonths (
|
|||
if (weekStart == 1)
|
||||
{
|
||||
view.add (Column::factory ("string.right", " "));
|
||||
view.add (Column::factory ("string.right", Date::dayName (1).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (2).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (3).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (4).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (5).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (6).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (0).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
|
||||
}
|
||||
else
|
||||
{
|
||||
view.add (Column::factory ("string.right", " "));
|
||||
view.add (Column::factory ("string.right", Date::dayName (0).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (1).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (2).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (3).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (4).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (5).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", Date::dayName (6).substr (0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
|
||||
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
26
src/utf8.cpp
26
src/utf8.cpp
|
@ -231,3 +231,29 @@ unsigned int utf8_text_length (const std::string& str)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string utf8_substr (
|
||||
const std::string& input,
|
||||
unsigned int start,
|
||||
unsigned int length /*=0*/)
|
||||
{
|
||||
// Find the starting index.
|
||||
std::string::size_type index_start = 0;
|
||||
for (unsigned int i = 0; i < start; i++)
|
||||
utf8_next_char (input, index_start);
|
||||
|
||||
std::string result;
|
||||
if (length)
|
||||
{
|
||||
std::string::size_type index_end = index_start;
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
utf8_next_char (input, index_end);
|
||||
|
||||
result = input.substr (index_start, index_end - index_start);
|
||||
}
|
||||
else
|
||||
result = input.substr (index_start);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -37,6 +37,7 @@ std::string utf8_character (unsigned int);
|
|||
int utf8_sequence (unsigned int);
|
||||
unsigned int utf8_length (const std::string&);
|
||||
unsigned int utf8_text_length (const std::string&);
|
||||
const std::string utf8_substr (const std::string&, unsigned int, unsigned int length = 0);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue