[Base-utils] i18n Parse Position doc 87/156887/4
authorTomasz Bochenski <t.bochenski@samsung.com>
Fri, 20 Oct 2017 10:51:49 +0000 (12:51 +0200)
committerEditor Lionbridge <TizenEditor.SEL@lionbridge.com>
Thu, 26 Oct 2017 13:20:00 +0000 (16:20 +0300)
PS2: Reviewed
PS3: Rebase
PS4: Fixed rebasing

Change-Id: I9977bde53baece73e5a057f33611f2eae866e520
Signed-off-by: Tomasz Bochenski <t.bochenski@samsung.com>
org.tizen.guides/html/native/internationalization/i18n_n.htm

index dd3f45c..c40a7c9 100644 (file)
@@ -1,4 +1,4 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
@@ -46,6 +46,7 @@
                        <li><a href="#field_pos">Field Identification in Formatted Output</a></li>
                        <li><a href="#format">String Format Management</a></li>
                        <li><a href="#measure">Measurement Values with Units</a></li>
+                       <li><a href="#parse_position">Parse Position Tracking</a></li>
                        <li><a href="#utmscale">Time Scale Conversion with Utmscale</a></li>
                        <li><a href="#uchar_iter">String Iteration with UCharIter</a></li>
                        <li><a href="#prerequisites">Prerequisites</a></li>
@@ -61,6 +62,7 @@
                        <li><a href="#field_pos_example">Managing the Field Position</a></li>
                        <li><a href="#format_examples">Managing String Formatting</a></li>
                        <li><a href="#measure_examples">Managing Measure Objects</a></li>
+                       <li><a href="#parse_position_examples">Managing the Parse Position</a></li>
                        <li><a href="#utmscale_examples">Converting Time Scales</a></li>
                        <li><a href="#manage_version">Retrieving the ICU Version</a></li>
                        <li><a href="#uchar_iter_examples">Iterating through Strings</a></li>
        <p>You can use the Format functions to <a href="#format">manage the string representations of objects or values</a>.</p></li>
        <li>Managing measurement values with units
        <p>You can <a href="#measure">store numeric measurement values with various units.</a></p></li>
+       <li>Tracking the parsing position
+       <p>You can <a href="#parse_position">track the current position while parsing</a> with ParsePosition.</p></li>
        <li>Converting time scales
        <p>You can <a href="#utmscale">convert datetimes between time scales</a> with Utmscale.</p></li>
        <li>Retrieving the ICU version
        <p>You can <a href="#manage_version">retrieve the currently-used version of the ICU library</a> with Uversion.</p></li>
        <li>Iterating through strings
-       <p>You can <a href="#uchar_iter">iterate through strings</a>, in a safe way, with UCharIter.</p>
-       </li>
+       <p>You can <a href="#uchar_iter">iterate through strings</a>, in a safe way, with UCharIter.</p></li>
 </ul>
 
        <div class="note">
        <strong>Note</strong>
-       The Alphabetic Index, FieldPosition, Format, Measure, and Utmscale APIs are supported since Tizen 3.0. The Uversion and UCharIter APIs are supported since Tizen 4.0.
+       The Alphabetic Index, FieldPosition, Format, Formattable, Measure, MeasureUnit, ParsePosition, and Utmscale APIs are supported since Tizen 3.0. The Uversion and UCharIter APIs are supported since Tizen 4.0.
        </div>
 
 <h2 id="ubrk" name="ubrk">Location Boundaries with Ubrk</h2>
        <li><code>newLanguage + newCountry + newVariant</code>
        <p>A valid ISO language code, ISO country code, and additional information on the variant. The variant codes are vendor and browser-specific. For example, use <code>WIN</code> for Windows, <code>MAC</code> for Macintosh, and <code>POSIX</code> for POSIX. Where there are 2 variants, separate them with an underscore, and put the most important one first. For example, a Traditional Spanish collation might be referenced, with <code>ES</code>, <code>ES</code>, <code>Traditional_WIN</code>.
 </p></li>
-       
+
 </ul>
 
 <p>
@@ -712,7 +715,7 @@ The measure objects can be formatted using the MeasureFormat API (in <a href="..
                <td>Gbit</td>
        </tr>
        <tr>
-               <td>gigbabyte</td>
+               <td>gigabyte</td>
                <td>GB</td>
        </tr>
        <tr>
@@ -1008,7 +1011,7 @@ The measure objects can be formatted using the MeasureFormat API (in <a href="..
        </tr>
        <tr>
                <td rowspan="3">Temperature</td>
-               <td>degree Celcius</td>
+               <td>degree Celsius</td>
                <td>&deg;C</td>
        </tr>
        <tr>
@@ -1111,6 +1114,11 @@ The measure objects can be formatted using the MeasureFormat API (in <a href="..
 </tbody>
 </table>
 
+<h2 id="parse_position" name="parse_position">Parse Position Tracking</h2>
+<p>The ParsePosition API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__PARSE__POSITION__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__PARSE__POSITION__MODULE.html">wearable</a> applications) is used by the Format API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__FORMAT__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__FORMAT__MODULE.html">wearable</a> applications) and the MeasureFormat API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__FORMAT__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__FORMAT__MODULE.html">wearable</a> applications) API to <a href="#parse_position_examples">track the current position while parsing</a>.</p>
+<p>The <code>xxx_parse_object()</code> functions require a parse position pointer as an argument. By design, you can use the same parse position pointer as you parse through a string with various formats, since the index parameter records the current position.</p>
+
+
 <h2 id="utmscale" name="utmscale">Time Scale Conversion with Utmscale</h2>
 <p>The Utmscale API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__UTMSCALE__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__UTMSCALE__MODULE.html">wearable</a> applications) allows you to <a href="#utmscale_examples">convert between time scales</a>.</p>
 <p>There are various conventions for binary datetime, depending on the platform and protocol. Some of these have severe drawbacks. For example, 32-bit Unix time (seconds since Jan 1, 1970) cannot support datetimes beyond the beginning of the year 2038. Arithmetic manipulations can also cause serious problems. For example, when calculating the average of 2 datetimes, if you calculate them with <code>average_time = (time1 + time2)/2</code>, there can be overflow even with dates around the present. Additionally, there is the issue of converting between different systems.</p>
@@ -2578,7 +2586,7 @@ int32_t index = 10; /* Index set after 10th character in source string */
 i18n_parse_position_create_with_index(index, &amp;parse_position);
 
 /* Parses from 10th character to next space character */
-i18n_format_parse_object_with_parse_position(format, source, parse_position, &amp;result); 
+i18n_format_parse_object_with_parse_position(format, source, parse_position, &amp;result);
 i18n_parse_position_destroy(parse_position);
 
 double value = 0;
@@ -2710,7 +2718,7 @@ i18n_measure_destroy(measure);
 </ol>
 
 <h3 id="measure_unit_examples" name="measure_unit_examples">Managing Measurement Units</h3>
-<p>You can use the MeasureUnit API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__UNIT__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__UNIT__MODULE.html">wearable</a> applications) to create measure unit objects, which can be passed to the Measure or MeasureFormat (in <a href="../../../../org.tizen.native.mobile.apireference//group__CAPI__BASE__UTILS__I18N__MEASURE__FORMAT__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference//group__CAPI__BASE__UTILS__I18N__MEASURE__FORMAT__MODULE.html">wearable</a> applications) APIs.</p>
+<p>You can use the MeasureUnit API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__UNIT__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__UNIT__MODULE.html">wearable</a> applications) to create measure unit objects, which can be passed to the Measure or MeasureFormat (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__FORMAT__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__MEASURE__FORMAT__MODULE.html">wearable</a> applications) APIs.</p>
 <ol>
 <li>To create a liter unit object:
 <pre class="prettyprint">
@@ -2743,7 +2751,7 @@ int32_t max = 20;
 i18n_measure_unit_h array[20];
 int32_t available;
 
-i18n_measure_unit_get_available(max, &amp;array, &amp;available); 
+i18n_measure_unit_get_available(max, &amp;array, &amp;available);
 </pre></li>
 <li>To retrieve the available units for a specific measure:
 <pre class="prettyprint">
@@ -2783,6 +2791,84 @@ i18n_measure_unit_destroy(unit);
 </pre></li>
 </ol>
 
+
+<h2 id="parse_position_examples" name="parse_position_examples">Managing the Parse Position</h2>
+<p>Since Tizen 3.0, you can use the ParsePosition API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__PARSE__POSITION__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__PARSE__POSITION__MODULE.html">wearable</a> applications) to track the current position while parsing.</p>
+<p>To manage the parse position:</p>
+<ol>
+<li>
+To create a parse position object:
+<ul>
+<li>
+Without specifying a position index:
+<pre class="prettyprint">
+i18n_parse_position_h parse_position;
+i18n_parse_position_create(&amp;parse_position);
+</pre>
+</li>
+<li>
+At a specific position index:
+<pre class="prettyprint">
+i18n_parse_position_h parse_position;
+i18n_parse_position_create_with_index(new_text_offset, &amp;parse_position);
+</pre>
+</li>
+</ul>
+</li>
+<li>
+To clone a parse position pointer:
+<pre class="prettyprint">
+i18n_parse_position_h parse_position_clone;
+i18n_parse_position_clone(parse_position, &amp;parse_position_clone);
+</pre>
+</li>
+<li>
+To manage the parse position index:
+<ul>
+<li>
+To set the index:
+<pre class="prettyprint">
+int32_t parse_position_index = 4;
+i18n_parse_position_set_index(parse_position, parse_position_index);
+</pre>
+</li>
+<li>
+To retrieve the index:
+<pre class="prettyprint">
+int32_t parse_position_index;
+i18n_parse_position_get_index(parse_position, &amp;parse_position_index);
+</pre>
+</li>
+</ul>
+</li>
+<li>
+To calculate the parsed length:
+<pre class="prettyprint">
+i18n_format_h num_format;
+i18n_uparse_error_s parse_err;
+i18n_unumber_create(I18N_UNUMBER_PERCENT, NULL, -1, I18N_ULOCALE_US, &amp;parse_err, &amp;num_format);
+
+i18n_parse_position_h parse position;
+i18n_parse_position_create_with_index(3, &amp;parse_position);
+
+i18n_formattable_h result;
+char* text_to_parse = "1234567%";
+int32_t begin;
+int32_t end;
+i18n_parse_position_get_index(parse_position, &amp;begin);
+i18n_format_parse_object_with_parse_position(num_format, text_to_parse, parse_position, &amp;result);
+i18n_parse_position_get_index(parse_position, &amp;end);
+
+int length = end - begin;
+</pre>
+</li>
+<li>
+When it is no longer needed, destroy the parse position object:
+<pre class="prettyprint">
+i18n_parse_position_destroy(parse_position);
+</pre>
+</li>
+</ol>
 <h2 id="utmscale_examples" name="utmscale_examples">Converting Time Scales</h2>
 <p>Since Tizen 3.0, you can use the Utmscale API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__BASE__UTILS__I18N__UTMSCALE__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__BASE__UTILS__I18N__UTMSCALE__MODULE.html">wearable</a> applications) to convert binary datetimes between various platform-dependent time scales.</p>
 <p>To convert a datetime value:</p>