c++ - How to parse kanji numeric characters using ICU? -
I am writing a function using ICU to parse a Unicode string in which Kanji is numeric character (K) And want to return the integer value of the string
"五" => 5
"三十 一" => 31
"五千 九百 七 十二" => 5972 < / P>
I'm setting locale for locale :: getJapan () and using the NumberFormat :: parse () to parse the character string. However, whenever I pass it to some kanji characters, then the pars () method is returning U_INVALID_FORMAT_ERROR.
Does anyone know that the ICU has supported the codepeed character string in the number format :: Pars () method? I was hoping that since I am setting locale in Japanese, then Kanji will be able to parse numerical values.
Thank you!
#include & lt; Iostream & gt; # Include & lt; Unicode / numfmt.h & gt; using namespace std; Int main (int arc, four ** argv) {core locale and jaLocale = locale :: mill (); UErrorCode Status = U_ZERO_ERROR; NumberFormat * nf = NumberFormat :: createInstance (Jellockel, Status); UChar number [] = {0x4E94}; // 'Unicode string' numStr (number) in Japanese '五' for character '5'; Formatting formatting; Nf- & gt; Parse (numStr, formatted, position); If (U_FAILURE (status)) {cout & lt; & Lt; "Parsing error as number:" & lt; & Lt; U_errorName (status) & lt; & Lt; Endl; Return (1); } Cout & lt; & Lt; "Long value:" & lt; & Lt; Formattable.getLong () & lt; & Lt; Endl; }
You can use the ICU Rule Based Number Format (RBNF) module rbnf.h For both (C ++) or C, with unum.h in the UNUM_SPELLOUT option, with both "J" locale for Japanese. Atrium provides your code for C ++ improvements: New Rule-Enhanced NAFormat (urbnf_splot, jellocale, status);
Comments
Post a Comment