Merge pull request #2079 from exeldro/startcase

obs-text: text transform add locale and start case
master
Jim 2019-11-15 02:07:07 -08:00 committed by GitHub
commit e6daa22ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -35,3 +35,4 @@ Transform="Text Transform"
Transform.None="None"
Transform.Uppercase="Uppercase"
Transform.Lowercase="Lowercase"
Transform.Startcase="Start Case"

View File

@ -80,6 +80,7 @@ using namespace Gdiplus;
#define S_TRANSFORM_NONE 0
#define S_TRANSFORM_UPPERCASE 1
#define S_TRANSFORM_LOWERCASE 2
#define S_TRANSFORM_STARTCASE 3
#define T_(v) obs_module_text(v)
#define T_FONT T_("Font")
@ -123,6 +124,7 @@ using namespace Gdiplus;
#define T_TRANSFORM_NONE T_("Transform.None")
#define T_TRANSFORM_UPPERCASE T_("Transform.Uppercase")
#define T_TRANSFORM_LOWERCASE T_("Transform.Lowercase")
#define T_TRANSFORM_STARTCASE T_("Transform.Startcase")
/* clang-format on */
@ -657,10 +659,28 @@ void TextSource::LoadFileText()
void TextSource::TransformText()
{
const locale loc = locale(obs_get_locale());
const ctype<wchar_t> &f = use_facet<ctype<wchar_t>>(loc);
if (text_transform == S_TRANSFORM_UPPERCASE)
transform(text.begin(), text.end(), text.begin(), towupper);
f.toupper(&text[0], &text[0] + text.size());
else if (text_transform == S_TRANSFORM_LOWERCASE)
transform(text.begin(), text.end(), text.begin(), towlower);
f.tolower(&text[0], &text[0] + text.size());
else if (text_transform == S_TRANSFORM_STARTCASE) {
bool upper = true;
for (wstring::iterator it = text.begin(); it != text.end();
++it) {
const wchar_t upper_char = f.toupper(*it);
const wchar_t lower_char = f.tolower(*it);
if (upper && lower_char != upper_char) {
upper = false;
*it = upper_char;
} else if (lower_char != upper_char) {
*it = lower_char;
} else {
upper = iswspace(*it);
}
}
}
}
#define obs_data_get_uint32 (uint32_t) obs_data_get_int
@ -951,6 +971,8 @@ static obs_properties_t *get_properties(void *data)
S_TRANSFORM_UPPERCASE);
obs_property_list_add_int(p, T_TRANSFORM_LOWERCASE,
S_TRANSFORM_LOWERCASE);
obs_property_list_add_int(p, T_TRANSFORM_STARTCASE,
S_TRANSFORM_STARTCASE);
obs_properties_add_bool(props, S_VERTICAL, T_VERTICAL);
obs_properties_add_color(props, S_COLOR, T_COLOR);