[Tizen] Rename tizen_string_utils to tizen_utils.

Add CodeFromISO369_2to_1 function.
This commit is contained in:
Sergey Pisarchik 2014-05-21 22:31:18 +03:00 committed by Alex Zolotarev
parent d4e00f5cd3
commit 953bf0335e
10 changed files with 267 additions and 38 deletions

View file

@ -3,7 +3,7 @@
#include "platform.hpp"
#include "http_thread_callback.hpp"
#include "tizen_string_utils.hpp"
#include "tizen_utils.hpp"
#include <FBaseColIEnumerator.h>

View file

@ -41,10 +41,10 @@ INCLUDEPATH += $$ROOT_DIR/3party/jansson/src
SOURCES += platform_android.cpp \
pthread_video_timer.cpp
} else:tizen* {
HEADERS += tizen_string_utils.hpp \
HEADERS += tizen_utils.hpp \
http_thread_tizen.hpp
SOURCES += platform_tizen.cpp \
tizen_string_utils.cpp \
tizen_utils.cpp \
pthread_video_timer.cpp \
http_thread_tizen.cpp \
}

View file

@ -12,7 +12,7 @@
#include "constants.hpp"
#include "platform_unix_impl.hpp"
#include "tizen_string_utils.hpp"
#include "tizen_utils.hpp"
#include "http_thread_tizen.hpp"
#include <FAppApp.h>

View file

@ -24,8 +24,7 @@
string GetAndroidSystemLanguage();
#elif defined(OMIM_OS_TIZEN)
// @TODO
#include "tizen_utils.hpp"
#else
#error "Define language preferences for your platform"
@ -174,8 +173,7 @@ void SystemPreferredLanguages(vector<string> & languages)
languages.push_back(GetAndroidSystemLanguage());
#elif defined(OMIM_OS_TIZEN)
// @TODO
languages.push_back(GetTizenLocale());
#else
#error "Define language preferences for your platform"
#endif

View file

@ -1,27 +0,0 @@
#include "tizen_string_utils.hpp"
#include "../../std/vector.hpp"
#include "../../tizen/inc/FBase.hpp"
string FromTizenString(Tizen::Base::String const & str_tizen)
{
string utf8Str;
if (str_tizen.GetLength() == 0)
return utf8Str;
Tizen::Base::ByteBuffer * pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen);
if (pBuffer)
{
int byteCount = pBuffer->GetLimit();
byteCount--; // Don't copy Zero at the end
if (byteCount > 0)
{
vector<char> chBuf(byteCount);
pBuffer->GetArray((byte *)&chBuf[0], 0, byteCount);
utf8Str.assign(chBuf.begin(), chBuf.end());
}
delete pBuffer;
}
return utf8Str;
}

256
platform/tizen_utils.cpp Normal file
View file

@ -0,0 +1,256 @@
#include "tizen_utils.hpp"
#include "../../std/vector.hpp"
#include "../../tizen/inc/FBase.hpp"
#include "../base/logging.hpp"
#include <FSystem.h>
string FromTizenString(Tizen::Base::String const & str_tizen)
{
string utf8Str;
if (str_tizen.GetLength() == 0)
return utf8Str;
Tizen::Base::ByteBuffer * pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen);
if (pBuffer)
{
int byteCount = pBuffer->GetLimit();
byteCount--; // Don't copy Zero at the end
if (byteCount > 0)
{
vector<char> chBuf(byteCount);
pBuffer->GetArray((byte *)&chBuf[0], 0, byteCount);
utf8Str.assign(chBuf.begin(), chBuf.end());
}
delete pBuffer;
}
return utf8Str;
}
string GetTizenLocale()
{
Tizen::Base::String languageCode;
Tizen::System::SettingInfo::GetValue(L"http://tizen.org/setting/locale.language", languageCode);
Tizen::Base::String languageCode_truncated;
languageCode.SubString(0, 3, languageCode_truncated);
return CodeFromISO369_2to_1(FromTizenString(languageCode_truncated));
}
string CodeFromISO369_2to_1(string const & code_ISO_639_2)
{
static const string ar [] =
{
"aar", "aa",
"abk", "ab",
"afr", "af",
"aka", "ak",
"sqi", "sq",
"amh", "am",
"ara", "ar",
"arg", "an",
"hye", "hy",
"asm", "as",
"ava", "av",
"ave", "ae",
"aym", "ay",
"aze", "az",
"bak", "ba",
"bam", "bm",
"eus", "eu",
"bel", "be",
"ben", "bn",
"bih", "bh",
"bis", "bi",
"bod", "bo",
"bos", "bs",
"bre", "br",
"bul", "bg",
"mya", "my",
"cat", "ca",
"ces", "cs",
"cha", "ch",
"che", "ce",
"zho", "zh",
"chu", "cu",
"chv", "cv",
"cor", "kw",
"cos", "co",
"cre", "cr",
"cym", "cy",
"ces", "cs",
"dan", "da",
"deu", "de",
"div", "dv",
"nld", "nl",
"dzo", "dz",
"ell", "el",
"eng", "en",
"epo", "eo",
"est", "et",
"eus", "eu",
"ewe", "ee",
"fao", "fo",
"fas", "fa",
"fij", "fj",
"fin", "fi",
"fra", "fr",
"fra", "fr",
"fry", "fy",
"ful", "ff",
"kat", "ka",
"deu", "de",
"gla", "gd",
"gle", "ga",
"glg", "gl",
"glv", "gv",
"ell", "el",
"grn", "gn",
"guj", "gu",
"hat", "ht",
"hau", "ha",
"heb", "he",
"her", "hz",
"hin", "hi",
"hmo", "ho",
"hrv", "hr",
"hun", "hu",
"hye", "hy",
"ibo", "ig",
"ice", "is",
"ido", "io",
"iii", "ii",
"iku", "iu",
"ile", "ie",
"ina", "ia",
"ind", "id",
"ipk", "ik",
"isl", "is",
"ita", "it",
"jav", "jv",
"jpn", "ja",
"kal", "kl",
"kan", "kn",
"kas", "ks",
"kat", "ka",
"kau", "kr",
"kaz", "kk",
"khm", "km",
"kik", "ki",
"kin", "rw",
"kir", "ky",
"kom", "kv",
"kon", "kg",
"kor", "ko",
"kua", "kj",
"kur", "ku",
"lao", "lo",
"lat", "la",
"lav", "lv",
"lim", "li",
"lin", "ln",
"lit", "lt",
"ltz", "lb",
"lub", "lu",
"lug", "lg",
"mkd", "mk",
"mah", "mh",
"mal", "ml",
"mri", "mi",
"mar", "mr",
"msa", "ms",
"mkd", "mk",
"mlg", "mg",
"mlt", "mt",
"mon", "mn",
"mri", "mi",
"msa", "ms",
"mya", "my",
"nau", "na",
"nav", "nv",
"nbl", "nr",
"nde", "nd",
"ndo", "ng",
"nep", "ne",
"nld", "nl",
"nno", "nn",
"nob", "nb",
"nor", "no",
"nya", "ny",
"oci", "oc",
"oji", "oj",
"ori", "or",
"orm", "om",
"oss", "os",
"pan", "pa",
"fas", "fa",
"pli", "pi",
"pol", "pl",
"por", "pt",
"pus", "ps",
"que", "qu",
"roh", "rm",
"ron", "ro",
"ron", "ro",
"run", "rn",
"rus", "ru",
"sag", "sg",
"san", "sa",
"sin", "si",
"slk", "sk",
"slk", "sk",
"slv", "sl",
"sme", "se",
"smo", "sm",
"sna", "sn",
"snd", "sd",
"som", "so",
"sot", "st",
"spa", "es",
"sqi", "sq",
"srd", "sc",
"srp", "sr",
"ssw", "ss",
"sun", "su",
"swa", "sw",
"swe", "sv",
"tah", "ty",
"tam", "ta",
"tat", "tt",
"tel", "te",
"tgk", "tg",
"tgl", "tl",
"tha", "th",
"bod", "bo",
"tir", "ti",
"ton", "to",
"tsn", "tn",
"tso", "ts",
"tuk", "tk",
"tur", "tr",
"twi", "tw",
"uig", "ug",
"ukr", "uk",
"urd", "ur",
"uzb", "uz",
"ven", "ve",
"vie", "vi",
"vol", "vo",
"cym", "cy",
"wln", "wa",
"wol", "wo",
"xho", "xh",
"yid", "yi",
"yor", "yo",
"zha", "za",
"zho", "zh",
"zul", "zu"
};
for (size_t i = 0; i < sizeof(ar)/sizeof(ar[0]); i += 2)
if (code_ISO_639_2 == ar[i])
{
return ar[i + 1];
}
LOG(LDEBUG, ("Language not found", code_ISO_639_2));
return "en";
}

View file

@ -13,5 +13,7 @@ namespace Tizen
//Convert from Tizen string to std::string
string FromTizenString(Tizen::Base::String const & str_tizen);
string CodeFromISO369_2to_1(string const & code_ISO_639_2);
string GetTizenLocale();
#endif

View file

@ -4,7 +4,7 @@
#include "AppResourceId.h"
#include "../../../base/logging.hpp"
#include "../../../platform/settings.hpp"
#include "../../../platform/tizen_string_utils.hpp"
#include "../../../platform/tizen_utils.hpp"
#include <FWeb.h>
#include <FAppApp.h>
#include <FApp.h>

View file

@ -3,7 +3,7 @@
#include "SettingsForm.hpp"
#include "AboutForm.hpp"
#include "../../../base/logging.hpp"
#include "../../../platform/tizen_string_utils.hpp"
#include "../../../platform/tizen_utils.hpp"
using namespace Tizen::Ui::Scenes;
using namespace Tizen::Base;

View file

@ -4,7 +4,7 @@
#include "SceneRegister.hpp"
#include "../../../map/framework.hpp"
#include "../../../gui/controller.hpp"
#include "../../../platform/tizen_string_utils.hpp"
#include "../../../platform/tizen_utils.hpp"
#include "../../../platform/settings.hpp"
#include <FUi.h>
#include <FBase.h>