コード例 #1
0
ファイル: locale_methods.c プロジェクト: vkywalker/php53-intl
/* {{{
* returns the position of a singleton if present 
* returns -1 if no singleton
* strtok equivalent search for singleton
*/
static int getSingletonPos(char* str)
{
	int result =-1;
	int i=0;
	int len = 0;
	
	if( str && ((len=strlen(str))>0) ){
		for( i=0; i<len ; i++){
			if( isIDSeparator(*(str+i)) ){
				if( i==1){
					/* string is of the form x-avy or a-prv1 */
					result =0;
					break;
				} else {
					/* delimiter found; check for singleton */
					if( isIDSeparator(*(str+i+2)) ){
						/* a singleton; so send the position of separator before singleton */
						result = i+1;
						break;
					}
				}
			}
		}/* end of for */
		
	}
	return result;
}
コード例 #2
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static int singleton_pos(const String& str) {
  auto len = str.size();
  for (int i = 0; i < (len - 2); ++i) {
    if (!isIDSeparator(str[i])) continue;
    if (i == 1) return 0;
    if (isIDSeparator(str[i+2])) return i+1;
  }
  return -1;
}
コード例 #3
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static String locale_suffix_strip(const String& locale) {
  for (int i = locale.size(); i >= 0; --i) {
    if (isIDSeparator(locale[i])) {
      if ((i>=2) && isIDSeparator(locale[i-2])) {
        return f_substr(locale, 0, i - 2);
      } else {
        return f_substr(locale, 0, i);
      }
    }
  }
  return null_string;
}
コード例 #4
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static void add_array_entry(Array& ret,
                            const String& locname,
                            LocaleTag tag) {
  Variant val;
  if (tag == LOC_PRIVATE) {
    val = get_private_subtags(locname);
  } else {
    val = get_icu_value(locname, tag, true);
  }
  if (val.isNull()) return;
  String strval = val.toString();
  if (strval.empty()) {
    return;
  }

  auto name = LocaleName(tag);
  if ((tag != LOC_PRIVATE) && (tag != LOC_VARIANT)) {
    ret.set(name, strval);
    return;
  }

  const char *s = strval.c_str(), *e = s + strval.size(), *p;
  int cnt;
  for (cnt = 0, p = s; p < e; ++p) {
    if (!isIDSeparator(*p)) continue;
    if ((p - s) > 1) {
      ret.set(name + String(cnt++), String(s, p - s, CopyString));
    }
    s = p + 1;
  }
  if ((e - s) > 1) {
    ret.set(name + String(cnt++), String(s, e - s, CopyString));
  }
}
コード例 #5
0
ファイル: locale_methods.c プロジェクト: vkywalker/php53-intl
/* {{{
* returns the position of next token for lookup 
* or -1 if no token
* strtokr equivalent search for token in reverse direction 
*/
static int getStrrtokenPos(char* str, int savedPos)
{
	int result =-1;
	int i;
	
	for(i=savedPos-1; i>=0; i--) {
		if(isIDSeparator(*(str+i)) ){
			/* delimiter found; check for singleton */
			if(i>=2 && isIDSeparator(*(str+i-2)) ){
				/* a singleton; so send the position of token before the singleton */
				result = i-2;
			} else {
				result = i;
			}
			break;
		}
	}
	if(result < 1){
		/* Just in case inavlid locale e.g. '-x-xyz' or '-sl_Latn' */
		result =-1;
	}
	return result;
}
コード例 #6
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static Array HHVM_STATIC_METHOD(Locale, getAllVariants, const String& locale) {
  Variant val = get_icu_value(localeOrDefault(locale), LOC_VARIANT);
  String strval = val.toString();
  if (strval.empty()) {
    return null_array;
  }
  Array ret = Array::Create();
  const char *s = strval.c_str(), *e = s + strval.size(), *p;
  for (p = s; p < e; ++p) {
    if (!isIDSeparator(*p)) continue;
    if ((p - s) <= 1) {
      return ret;
    }
    ret.append(String(s, p - s, CopyString));
    s = p + 1;
  }
  if ((e - s) > 1) {
    ret.append(String(s, e - s, CopyString));
  }
  return ret;
}