[前][次][番号順一覧][スレッド一覧]

ruby-changes:33976

From: nobu <ko1@a...>
Date: Fri, 23 May 2014 13:44:18 +0900 (JST)
Subject: [ruby-changes:33976] nobu:r46057 (trunk): enc/unicode.c: lookup functions

nobu	2014-05-23 13:44:15 +0900 (Fri, 23 May 2014)

  New Revision: 46057

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46057

  Log:
    enc/unicode.c: lookup functions
    
    * enc/unicode.c (onigenc_unicode_{fold,unfold{1,2,3}}_lookup):
      abstract lookup functions.

  Modified files:
    trunk/enc/unicode.c
Index: enc/unicode.c
===================================================================
--- enc/unicode.c	(revision 46056)
+++ enc/unicode.c	(revision 46057)
@@ -292,6 +292,46 @@ static int init_case_fold_table(void) https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L292
   return 0;
 }
 
+static inline const CodePointList3 *
+onigenc_unicode_fold_lookup(OnigCodePoint code)
+{
+  st_data_t to;
+  if (onig_st_lookup(FoldTable, (st_data_t)code, &to) != 0) {
+    return (const CodePointList3 *)to;
+  }
+  return 0;
+}
+
+static inline const CodePointList3 *
+onigenc_unicode_unfold1_lookup(OnigCodePoint code)
+{
+  st_data_t to;
+  if (onig_st_lookup(Unfold1Table, (st_data_t )code, &to) != 0) {
+    return (const CodePointList3 *)to;
+  }
+  return 0;
+}
+
+static inline const CodePointList2 *
+onigenc_unicode_unfold2_lookup(const OnigCodePoint *code)
+{
+  st_data_t to;
+  if (onig_st_lookup(Unfold2Table, (st_data_t )code, &to) != 0) {
+    return (const CodePointList2 *)to;
+  }
+  return 0;
+}
+
+static inline const CodePointList2 *
+onigenc_unicode_unfold3_lookup(const OnigCodePoint *code)
+{
+  st_data_t to;
+  if (onig_st_lookup(Unfold3Table, (st_data_t )code, &to) != 0) {
+    return (const CodePointList2 *)to;
+  }
+  return 0;
+}
+
 extern int
 onigenc_unicode_mbc_case_fold(OnigEncoding enc,
     OnigCaseFoldType flag ARG_UNUSED, const UChar** pp, const UChar* end,
@@ -319,7 +359,7 @@ onigenc_unicode_mbc_case_fold(OnigEncodi https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L359
   }
 #endif
 
-  if (onig_st_lookup(FoldTable, (st_data_t )code, (void* )&to) != 0) {
+  if ((to = onigenc_unicode_fold_lookup(code)) != 0) {
     if (to->n == 1) {
       return ONIGENC_CODE_TO_MBC(enc, to->code[0], fold);
     }
@@ -528,7 +568,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L568
   }
 #endif
 
-  if (onig_st_lookup(FoldTable, (st_data_t )code, (void* )&to) != 0) {
+  if ((to = onigenc_unicode_fold_lookup(code)) != 0) {
     if (to->n == 1) {
       OnigCodePoint orig_code = code;
 
@@ -538,7 +578,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L578
       n++;
 
       code = to->code[0];
-      if (onig_st_lookup(Unfold1Table, (st_data_t )code, (void* )&to) != 0) {
+      if ((to = onigenc_unicode_unfold1_lookup(code)) != 0) {
 	for (i = 0; i < to->n; i++) {
 	  if (to->code[i] != orig_code) {
 	    items[n].byte_len = len;
@@ -555,8 +595,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L595
 
       for (fn = 0; fn < to->n; fn++) {
 	cs[fn][0] = to->code[fn];
-	if (onig_st_lookup(Unfold1Table, (st_data_t )cs[fn][0],
-			   (void* )&z3) != 0) {
+	if ((z3 = onigenc_unicode_unfold1_lookup(cs[fn][0])) != 0) {
 	  for (i = 0; i < z3->n; i++) {
 	    cs[fn][i+1] = z3->code[i];
 	  }
@@ -577,8 +616,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L616
 	  }
 	}
 
-	if (onig_st_lookup(Unfold2Table, (st_data_t )to->code,
-			   (void* )&z2) != 0) {
+	if ((z2 = onigenc_unicode_unfold2_lookup(to->code)) != 0) {
 	  for (i = 0; i < z2->n; i++) {
 	    if (z2->code[i] == code) continue;
 
@@ -603,8 +641,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L641
 	  }
 	}
 
-	if (onig_st_lookup(Unfold3Table, (st_data_t )to->code,
-			   (void* )&z2) != 0) {
+	if ((z2 = onigenc_unicode_unfold3_lookup(to->code)) != 0) {
 	  for (i = 0; i < z2->n; i++) {
 	    if (z2->code[i] == code) continue;
 
@@ -621,7 +658,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L658
     }
   }
   else {
-    if (onig_st_lookup(Unfold1Table, (st_data_t )code, (void* )&to) != 0) {
+    if ((to = onigenc_unicode_unfold1_lookup(code)) != 0) {
       for (i = 0; i < to->n; i++) {
 	items[n].byte_len = len;
 	items[n].code_len = 1;
@@ -639,7 +676,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L676
 
       codes[0] = code;
       code = ONIGENC_MBC_TO_CODE(enc, p, end);
-      if (onig_st_lookup(FoldTable, (st_data_t )code, (void* )&to) != 0
+      if ((to = onigenc_unicode_fold_lookup(code)) != 0
 	  && to->n == 1) {
 	codes[1] = to->code[0];
       }
@@ -648,7 +685,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L685
 
       clen = enclen(enc, p, end);
       len += clen;
-      if (onig_st_lookup(Unfold2Table, (st_data_t )codes, (void* )&z2) != 0) {
+      if ((z2 = onigenc_unicode_unfold2_lookup(codes)) != 0) {
 	for (i = 0; i < z2->n; i++) {
 	  items[n].byte_len = len;
 	  items[n].code_len = 1;
@@ -660,7 +697,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L697
       p += clen;
       if (p < end) {
 	code = ONIGENC_MBC_TO_CODE(enc, p, end);
-	if (onig_st_lookup(FoldTable, (st_data_t )code, (void* )&to) != 0
+	if ((to = onigenc_unicode_fold_lookup(code)) != 0
 	    && to->n == 1) {
 	  codes[2] = to->code[0];
 	}
@@ -669,8 +706,7 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L706
 
 	clen = enclen(enc, p, end);
 	len += clen;
-	if (onig_st_lookup(Unfold3Table, (st_data_t )codes,
-			   (void* )&z2) != 0) {
+	if ((z2 = onigenc_unicode_unfold3_lookup(codes)) != 0) {
 	  for (i = 0; i < z2->n; i++) {
 	    items[n].byte_len = len;
 	    items[n].code_len = 1;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]