void test_operator() { printf( ">>>>>>>>> 연산자\n" ); CUString str1 ="hello"; CUString str2 = "bye"; printf( "문자열1:%s\n", str1.GetStr() ); printf( "문자열2:%s\n", str2.GetStr() ); // + CUString str = str1 + str2; printf( "operator +: %s\n", str.GetStr() ); // += str += " ^^;"; printf( "operator +=: %s\n", str.GetStr() ); // == printf( "operator ==: " ); str = "hello"; if( str == "hello" ) { printf( "%s == hello\n", str.GetStr() ); } // += printf( "operator !=: " ); str = "hello"; if( str != "___" ) { printf( "%s != ___\n", str.GetStr() ); } printf( "\n" ); }
void test_debug() { CUString t= "ab안녕하세요cd"; printf( "%s\n", t.GetStr() ); printf( "%d\n", t.GetLength() ); printf( "%d\n", t.GetCharLength() ); CUString str_org = "adk안녕하세요zzz"; CUString str = str_org.GetChar(-2); printf( "[%s]\n", str.GetStr() ); CUString str_org2 = "adk안녕하세요zzz"; CUString str2 = str_org2.GetChars(-2,2); printf( "[%s]\n", str2.GetStr() ); CUString str_org3 = "adk안녕하세요zzz"; int diff = str_org3.DeleteChars(3,400); printf( "[%s]%d\n", str_org3.GetStr(), diff ); CUString rev_test = "abcd1a234"; int find = rev_test.ReverseFind( '4' ); printf( "[%s]%d\n", rev_test.GetStr(), find ); str = "a b"; str.Replace( " ", " " ); printf( "%s\n", str.GetStr() ); }
void test_del() { CUString str = "hello<TAG>this should be deleted.</TAG>bye and <TAG>this also</TAG>bye"; fprintf( stderr, "before:%s\n", str.GetStr() ); int cnt = str.DeleteBoundTag( "<TAG>", "</TAG>" ); fprintf( stderr, "after :%s\n%d", str.GetStr(), cnt ); fprintf( stderr, "\n"); fprintf( stderr, "\n"); }
void load( char *prefix, char *key ) { CUMGT mgt; if( mgt.Load( prefix ) == false ) { fprintf( stderr, "Error: fail to load %s\n", prefix ); return; } fprintf( stderr, "Record: %d\n", mgt.GetNumRecord() ); CUMGTInfo info; if( mgt.GetInfo( key, info ) == false ) { fprintf( stderr, "No key: %s\n", key ); } else { CUString ret; if( mgt.GetContent( info, ret ) == false ) { fprintf( stderr, "Fail to get content\n" ); } else { fprintf( stdout, "%s", ret.GetStr() ); } } }
void test_replace() { printf( ">>>>>>>>> Replace 테스트\n" ); CUString str; str = "hello this is my ... "; int num = str.Replace( "...", "" ); str.Print( stderr ); fprintf( stderr, "%s[%d]\n",str.GetStr(), num ); printf( "\n" ); }
void replace_test() { CUString str; str = "hello this is my ... "; str = "abababab___"; int num = str.Replace( "aba", "$" ); str.Print( stderr ); fprintf( stderr, "%s[%d]\n",str.GetStr(), num ); }
void test_checknum() { printf( ">>>>>>>>> 숫자체크\n" ); CUString str; str="123344"; if(str.IsNumber() ) { fprintf(stderr, "%s is number\n", str.GetStr() ); } else { fprintf(stderr, "%s is not number\n", str.GetStr() ); } str="12,344"; if(str.IsNumber() ) { fprintf(stderr, "%s is number\n", str.GetStr() ); } else { fprintf(stderr, "%s is not number\n", str.GetStr() ); } str="1344하이"; if(str.IsNumber() ) { fprintf(stderr, "%s is number\n", str.GetStr() ); } else { fprintf(stderr, "%s is not number\n", str.GetStr() ); } printf( "\n" ); }
bool CUIndexFile::Load( char *prefix ) { Close(); char buf[1024]; sprintf( buf, "%s.uidx-key", prefix ); if( key_file.OpenFile( buf, "r" ) == false ) { return false; } sprintf( buf, "%s.uidx-value", prefix ); if( value_file.OpenFile( buf, "r" ) == false ) { return false; } info_map.clear(); while( true ) { CUString line; if( key_file.ReadLine( line ) == false ) break; CUStringList list( line, "\t" ); if( list.GetSize() != 4 ) { fprintf( stderr, "Error: Invalid format: %s\n", line.GetStr() ); return false; } if( info_map.find( list.GetAt(0) ) != info_map.end() ) { fprintf( stderr, "Error: Duplicated key: %s\n", list.GetAt(0) ); return false; } CUIndexFileInfo info; info.start = atol( list.GetAt(1) ); info.end = atol( list.GetAt(2) ); if( strcmp( list.GetAt(3), "0" ) == 0 ) info.enable = false; else info.enable = true; info_map[ list.GetAt(0) ] = info; } return true; }
CUString EncodeUTF8( CUString &str ) { CUString ret = ""; if( str.GetLength() == 6 ) { ret = str.SubStr( 2,6 ); unsigned long index; index = strtoul( ret.GetStr(), 0, 16 ); if( 0x00 <= index && index <= 0x7F ) { char buf[4]; sprintf( buf, "%c", (char)index ); ret = buf; } else if( 0x80 <= index && index <= 0x07FF ) { // 2byte; int enc_ch1 = 0xC0; // 11000000 int enc_ch2 = 0x80; // 10000000 char ch1 = (char)strtoul( ret.SubStr(0,2).GetStr(), 0, 16 ); char ch2 = (char)strtoul( ret.SubStr(2,4).GetStr(), 0, 16 ); if( ch1 & (1 << (3-1) ) ) { enc_ch1 |= (1 << (5-1) ); } if( ch1 & (1 << (2-1) ) ) { enc_ch1 |= (1 << (4-1) ); } if( ch1 & (1 << (1-1) ) ) { enc_ch1 |= (1 << (3-1) ); } if( ch2 & (1 << (8-1) ) ) { enc_ch1 |= (1 << (2-1) ); } if( ch2 & (1 << (7-1) ) ) { enc_ch1 |= (1 << (1-1) ); } if( ch2 & (1 << (6-1) ) ) { enc_ch2 |= (1 << (6-1) ); } if( ch2 & (1 << (5-1) ) ) { enc_ch2 |= (1 << (5-1) ); } if( ch2 & (1 << (4-1) ) ) { enc_ch2 |= (1 << (4-1) ); } if( ch2 & (1 << (3-1) ) ) { enc_ch2 |= (1 << (3-1) ); } if( ch2 & (1 << (2-1) ) ) { enc_ch2 |= (1 << (2-1) ); } if( ch2 & (1 << (1-1) ) ) { enc_ch2 |= (1 << (1-1) ); } //dumptoBin( enc_ch1 ); dumptoBin( enc_ch2 ); char buf[4]; sprintf( buf, "%c%c", enc_ch1, enc_ch2 ); ret = buf; } else if( 0x0800 <= index && index <= 0xFFFF ) { // 3byte; char enc_ch1 = 0xE0; // 11100000 char enc_ch2 = 0x80; // 10000000 char enc_ch3 = 0x80; // 10000000 char ch1 = (char)strtoul( ret.SubStr(0,2).GetStr(), 0, 16 ); char ch2 = (char)strtoul( ret.SubStr(2,4).GetStr(), 0, 16 ); if( ch1 & (1 << (8-1) ) ) { enc_ch1 |= (1 << (4-1) ); } if( ch1 & (1 << (7-1) ) ) { enc_ch1 |= (1 << (3-1) ); } if( ch1 & (1 << (6-1) ) ) { enc_ch1 |= (1 << (2-1) ); } if( ch1 & (1 << (5-1) ) ) { enc_ch1 |= (1 << (1-1) ); } if( ch1 & (1 << (4-1) ) ) { enc_ch2 |= (1 << (6-1) ); } if( ch1 & (1 << (3-1) ) ) { enc_ch2 |= (1 << (5-1) ); } if( ch1 & (1 << (2-1) ) ) { enc_ch2 |= (1 << (4-1) ); } if( ch1 & (1 << (1-1) ) ) { enc_ch2 |= (1 << (3-1) ); } if( ch2 & (1 << (8-1) ) ) { enc_ch2 |= (1 << (2-1) ); } if( ch2 & (1 << (7-1) ) ) { enc_ch2 |= (1 << (1-1) ); } if( ch2 & (1 << (6-1) ) ) { enc_ch3 |= (1 << (6-1) ); } if( ch2 & (1 << (5-1) ) ) { enc_ch3 |= (1 << (5-1) ); } if( ch2 & (1 << (4-1) ) ) { enc_ch3 |= (1 << (4-1) ); } if( ch2 & (1 << (3-1) ) ) { enc_ch3 |= (1 << (3-1) ); } if( ch2 & (1 << (2-1) ) ) { enc_ch3 |= (1 << (2-1) ); } if( ch2 & (1 << (1-1) ) ) { enc_ch3 |= (1 << (1-1) ); } //dumptoBin( enc_ch1 ); dumptoBin( enc_ch2 ); dumptoBin( enc_ch3 ); char buf[4]; sprintf( buf, "%c%c%c", enc_ch1, enc_ch2, enc_ch3 ); ret = buf; } } return ret; }
bool CDecoder::LoadFoundation( CUOption* option ) { if( option == NULL ) return false; this->option = option; // check options CUString key="foundation"; CUString foundation_dn; if( option->GetValue( key, foundation_dn ) == false ) { fprintf( stderr, "Required option is not defined: foundation\n" ); return false; } this->foundation_dn = foundation_dn; char fn[1024]; sprintf( fn ,"%s/pair.utf8", foundation_dn.GetStr() ); CUTextFile file( fn, "r" ); if( file.CheckOpen() == false ) return false; CUString content; file.LoadToStr( content ); CUStringListRO content_list( content, "\n" ); if( content_list.GetSize() < 4 ) { fprintf( stderr, "Error: Invalid pair.utf\n" ); return false; } src_org = content_list.GetAt(0); tgt_org = content_list.GetAt(1); src_tok = content_list.GetAt(2); tgt_tok = content_list.GetAt(3); // load trans tree CUStringListRO src_tok_list( src_tok, " " ); trans_tree.Set( src_tok_list ); for( int i=4; i<content_list.GetSize(); i++ ) { CUString str = content_list.GetAt(i); if( str.Find( "S-P\t") == 0 ) { CUStringListRO tmp_list( str.Mid(4), ":" ); if( trans_tree.ApplyParse( tmp_list ) == false ) { fprintf( stderr, "Error: Invalid parse rule: %s\n", str.GetStr() ); return false; } else { //trans_tree.Print( stderr ); } } } // apply trans rule for( int i=4; i<content_list.GetSize(); i++ ) { CUString str = content_list.GetAt(i); if( str.Find( "TR\t") == 0 ) { CUStringListRO tmp_list( str.Mid(3), "\t" ); if( trans_tree.ApplyTransRule( tmp_list ) == false ) { fprintf( stderr, "Error: Invalid parse rule: %s\n", str.GetStr() ); return false; } else { //trans_tree.Print( stderr ); } } } // apply trans rule for( int i=4; i<content_list.GetSize(); i++ ) { CUString str = content_list.GetAt(i); if( str.Find( "TL\t") == 0 ) { CUStringListRO tmp_list( str.Mid(3), "\t" ); if( trans_tree.ApplyTransLexical( tmp_list ) == false ) { fprintf( stderr, "Error: Invalid parse lexical: %s\n", str.GetStr() ); return false; } else { //trans_tree.Print( stderr ); } } } trans_tree.OrderByTrans(); trans_tree.Print( stderr ); CUString trans_str = trans_tree.GetTransStr(); CUStringListRO tmp1( tgt_tok, " " ); fprintf( stderr, "TGT: " ); for( int i=0; i<tmp1.GetSize(); i++ ) { CUString tmp = tmp1.GetAt(i); fprintf( stderr, " %s", tmp.Left( tmp.ReverseFind('/') ).GetStr() ); } fprintf( stderr, "\n" ); CUStringListRO tmp2( trans_str, " " ); fprintf( stderr, "OUT: " ); for( int i=0; i<tmp2.GetSize(); i++ ) { CUString tmp = tmp2.GetAt(i); fprintf( stderr, " %s", tmp.Left( tmp.ReverseFind('/') ).GetStr() ); } fprintf( stderr, "\n" ); return true; }
bool CUStringNode::SetData( CUString &arg_str ) { return SetData( (char*)arg_str.GetStr() ); }