Permalink
Browse files

Deal with case result generation separately

  • Loading branch information...
1 parent 5e3623c commit d29ba33a2a04c93748b8e15774a9c43c05c448b8 Nikolai Weibull committed Apr 7, 2013
Showing with 437 additions and 546 deletions.
  1. +5 −15 ext/u/attributes.c
  2. +2 −1 ext/u/attributes.h
  3. +39 −0 ext/u/case.h
  4. +191 −200 ext/u/depend
  5. +47 −0 ext/u/output.h
  6. +0 −10 ext/u/private.h
  7. +5 −0 ext/u/u.h
  8. +78 −165 ext/u/u_downcase.c
  9. +1 −0 ext/u/u_locale.c
  10. +28 −48 ext/u/u_titlecase.c
  11. +39 −107 ext/u/u_upcase.c
  12. +2 −0 lib/u/version.rb
View
@@ -38,21 +38,11 @@ _u_special_case_table_lookup(uint32_t c)
/* {{{1
* Output titlecases where appropriate.
*/
-size_t
-_u_special_case_output(char *buf, int offset, int type, bool upper)
+const char *
+_u_special_case(uint32_t v, enum u_general_category category, bool upper)
{
- const char *p = _u_special_case_table + offset;
-
- if (type != U_GENERAL_CATEGORY_LETTER_TITLECASE)
+ const char *p = _u_special_case_table + v - UNICODE_SPECIAL_CASE_TABLE_START;
+ if (category != U_GENERAL_CATEGORY_LETTER_TITLECASE)
p = u_next(p);
-
- if (upper)
- p += u_n_bytes(p) + 1;
-
- size_t n = u_n_bytes(p);
-
- if (buf != NULL)
- memcpy(buf, p, n);
-
- return n;
+ return upper ? p + u_n_bytes(p) + 1 : p;
}
View
@@ -22,4 +22,5 @@ s_attribute(uint32_t c)
}
uint32_t _u_special_case_table_lookup(uint32_t c);
-size_t _u_special_case_output(char *buf, int offset, int type, bool upper);
+const char *_u_special_case(uint32_t v, enum u_general_category category,
+ bool upper);
View
@@ -0,0 +1,39 @@
+void _u_downcase_step(const char *string, const char *p,
+ const char *end, bool use_end,
+ enum locale locale, struct output *output);
+
+void _u_upcase_step(const char *string, const char **p,
+ const char *end, bool use_end,
+ enum locale locale, bool title, struct output *output);
+
+static inline void
+case_simple(uint32_t c, enum u_general_category category, bool title, bool upper, struct output *output)
+{
+ uint32_t v = s_attribute(c);
+ uint32_t u;
+ if (v >= UNICODE_SPECIAL_CASE_TABLE_START)
+ output_zstring(output, _u_special_case(v, category, title));
+ else if (category == U_GENERAL_CATEGORY_LETTER_TITLECASE &&
+ (u = _u_titlecase_table_lookup(c, upper)) != c)
+ output_char(output, u);
+ else
+ output_char(output, v != '\0' ? v : c);
+}
+
+static inline bool
+is_after(const char *string, const char *p, bool predicate(uint32_t))
+{
+ if (p == string)
+ return false;
+ for (const char *q = u_prev(p); q > string; q = u_prev(q)) {
+ uint32_t c = u_dref(q);
+ if (predicate(c))
+ return true;
+ switch (u_char_combining_class(u_dref(p))) {
+ case U_CANONICAL_COMBINING_CLASS_ABOVE:
+ case U_CANONICAL_COMBINING_CLASS_NOT_REORDERED:
+ return false;
+ }
+ }
+ return predicate(u_dref(string));
+}
Oops, something went wrong. Retry.

0 comments on commit d29ba33

Please sign in to comment.