• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2012 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #include "SkLanguage.h"
10 
11 #ifdef SK_BUILD_FOR_ANDROID // currently only for Android
12 
13 #include "SkTDict.h"
14 #include "SkThread.h"
15 #include <cstring>
16 
getParent() const17 SkLanguage SkLanguage::getParent() const {
18     SkASSERT(fInfo != NULL);
19     SkASSERT(fInfo->fTag != NULL);
20     const char* tag = fInfo->fTag.c_str();
21     SkASSERT(tag != NULL);
22 
23     // strip off the rightmost "-.*"
24     char* parentTagEnd = strrchr(tag, '-');
25     if (parentTagEnd == NULL) {
26         return SkLanguage("");
27     }
28     size_t parentTagLen = parentTagEnd - tag;
29     char parentTag[parentTagLen + 1];
30     strncpy(parentTag, tag, parentTagLen);
31     parentTag[parentTagLen] = '\0';
32     return SkLanguage(parentTag);
33 }
34 
35 SK_DECLARE_STATIC_MUTEX(gGetInfoMutex);
getInfo(const char * tag)36 const SkLanguageInfo* SkLanguage::getInfo(const char* tag) {
37     SkAutoMutexAcquire lock(gGetInfoMutex);
38 
39     static const size_t kDictSize = 128;
40     static SkTDict<SkLanguageInfo*> tagToInfo(kDictSize);
41 
42     // try a lookup
43     SkLanguageInfo* info;
44     if (tagToInfo.find(tag, &info)) {
45         return info;
46     }
47 
48     // no match - add this language
49     info = new SkLanguageInfo(tag);
50     tagToInfo.set(tag, info);
51     return info;
52 }
53 
54 #endif
55