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 17SkLanguage SkLanguage::getParent() const { 18 SkASSERT(fInfo != NULL); 19 const char* tag = fInfo->fTag.c_str(); 20 SkASSERT(tag != NULL); 21 22 // strip off the rightmost "-.*" 23 char* parentTagEnd = strrchr(tag, '-'); 24 if (parentTagEnd == NULL) { 25 return SkLanguage(""); 26 } 27 size_t parentTagLen = parentTagEnd - tag; 28 char parentTag[parentTagLen + 1]; 29 strncpy(parentTag, tag, parentTagLen); 30 parentTag[parentTagLen] = '\0'; 31 return SkLanguage(parentTag); 32} 33 34SK_DECLARE_STATIC_MUTEX(gGetInfoMutex); 35const SkLanguageInfo* SkLanguage::getInfo(const char* tag) { 36 SkAutoMutexAcquire lock(gGetInfoMutex); 37 38 static const size_t kDictSize = 128; 39 static SkTDict<SkLanguageInfo*> tagToInfo(kDictSize); 40 41 // try a lookup 42 SkLanguageInfo* info; 43 if (tagToInfo.find(tag, &info)) { 44 return info; 45 } 46 47 // no match - add this language 48 info = new SkLanguageInfo(tag); 49 tagToInfo.set(tag, info); 50 return info; 51} 52 53#endif 54