From 912f84114e4b9060af7b611235701148dab3cc39 Mon Sep 17 00:00:00 2001 From: Jozef Marek Date: Tue, 11 Aug 2015 14:02:41 +0200 Subject: [PATCH] [Tutorial][Base-Utils] Uset: add strings scenario Change-Id: I98d826892afab3d3485b4c7a7d6c7938738d66fd Signed-off-by: Jozef Marek --- .../html/native/base/i18n_tutorial_n.htm | 64 +++++++++++++++++----- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/org.tizen.tutorials/html/native/base/i18n_tutorial_n.htm b/org.tizen.tutorials/html/native/base/i18n_tutorial_n.htm index 79be505..09c14c5 100644 --- a/org.tizen.tutorials/html/native/base/i18n_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/base/i18n_tutorial_n.htm @@ -375,19 +375,19 @@ i18n_uchar substring[BUFLEN]; i18n_uchar *result = i18n_ustring_string(s, substr); -if (result == NULL) +if (result == NULL) {    dlog_print(DLOG_DEBUG, LOG_TAG, "Substring not found"); -} -else +} +else {    dlog_print(DLOG_DEBUG, LOG_TAG, "Substring index: %d", result - s); -} +} - +

Managing Dates and Calendar

@@ -620,7 +620,7 @@ const char * locale = i18n_unumber_get_locale_by_type(num_format, I18N_ULOCALE_D i18n_ubreak_iterator_h boundary; const char *str = "Twinkle, twinkle little star" i18n_uchar* stringToExamine = malloc(sizeof(i18n_uchar)*28); -i18n_ustring_copy_ua(stringToExamine, str); +i18n_ustring_copy_ua(stringToExamine, str); i18n_ubrk_create(I18N_UBRK_WORD, "en_US", stringToExamine, i18n_ustring_get_length(stringToExamine), &boundary); @@ -630,7 +630,7 @@ i18n_ubrk_create(I18N_UBRK_WORD, "en_US", stringToExamine, i18n_ustrin int32_t start = i18n_ubrk_first(boundary); int32_t end = i18n_ubrk_next(boundary); -

The start and end represent the boundaries of the first word, in this example 0 and 7.

+

The start and end represent the boundaries of the first word, in this example 0 and 7.

  • Retrieve the string.

    @@ -691,7 +691,7 @@ const char *element = NULL; int len; element = i18n_uenumeration_next(strings_enum, &len); -while (element != NULL) +while (element != NULL) {    // Use the returned string @@ -727,7 +727,7 @@ const char *tz = NULL; int len; tz = i18n_uenumeration_next(timezones, &len); -while (tz != NULL) +while (tz != NULL) {    // Use the time zone string @@ -753,7 +753,7 @@ const char *sk = NULL; int len; sk = i18n_uenumeration_next(skeletons, &len); -while (sk != NULL) +while (sk != NULL) {    // Use the skeleton string @@ -776,7 +776,7 @@ const char *keyword = NULL; int len; keyword = i18n_uenumeration_next(keywords, &len); -while (keyword != NULL) +while (keyword != NULL) {    // Use the keyword string @@ -862,7 +862,7 @@ i18n_uset_create_empty(&set);
  • -

    Managing characters

    +

    Managing characters

    The set can contain characters as its elements. It's also possible to check if a set contains specified characters.

    1. @@ -911,10 +911,48 @@ i18n_uset_h compare_set = NULL; i18n_ubool contains_character = i18n_uset_contains_all(set, compare_set);
    2. +
    +

    Managing strings

    +

    The set can contain strings as its elements:

    +
      +
    1. +Add a string to the set: +
      +const char *text = "Example string";
      +i18n_uchar u_input_text[BUFLEN];
      +i18n_ustring_copy_ua(u_input_text, text);
       
      +i18n_uset_add_string(set, u_input_text, -1);
      +
      +The entire string is a single element in such cases. +
    2. +
    3. +List all strings in the set: +
      +int strings_count = i18n_uset_get_item_count(set);
      +int32_t len = 0;
      +int32_t i;
      +for (i = 0; i < strings_count; ++i) {
      +    i18n_uchar32 start, end;
      +    i18n_uchar string[100];
      +    let = i18n_uset_get_item(set, i, &start, &end, string, 100);
      +    if (len != 0) {
      +        // a string was found, use the 'string' variable
      +    }
      +}
      +
      +Note that the i18n_uset_get_item() function also returns ranges (an item is a string or a range). The return value is 0 if the current item is a range. Please refer to the documentation for details. +
    4. +
    5. +Check whether the set contains a string: +
      +i18n_ubool contains = i18n_uset_contains_string(set, input_ustring, -1);
      +
      +
    - + + -- 2.7.4