Develop and Download Open Source Software

Browse Subversion Repository

Contents of /jpinput/RomanCreator.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 336 - (show annotations) (download) (as text)
Sun Apr 6 21:40:53 2008 UTC (16 years, 1 month ago) by satofumi
File MIME type: text/x-c++src
File size: 2373 byte(s)
convert string: char -> Uint16
1 /*!
2 \file
3 \brief ƒ[ƒ}Žš“ü—ÍŒó•â‚ւ̕ϊˇ
4
5 \author Satofumi KAMIMURA
6
7 $Id$
8 */
9
10 #include "RomanCreator.h"
11 #include "RomanConvertTable.h"
12 #include "UtfString.h"
13 #include <string>
14
15 using namespace beego;
16
17
18 struct RomanCreator::pImpl {
19 const Uint16* convert_table;
20 unsigned int max_length;
21 std::basic_string<Uint16> converted;
22 std::vector<Uint16> converted_char;
23
24 pImpl(const Uint16* convertTable, unsigned int maxLength)
25 : convert_table(convertTable), max_length(maxLength) {
26 }
27
28 size_t ptnlen(const int index, const Uint16* table) {
29 int length = 0;
30 while (table[index + length] != 0x0) {
31 ++length;
32 }
33 return length;
34 }
35
36 size_t replace(size_t match_index, int table_index) {
37 size_t ptn_length = ptnlen(table_index, convert_table);
38 converted.replace(match_index, ptn_length,
39 &convert_table[table_index - max_length]);
40
41 return ptn_length - ptnlen(table_index - max_length, convert_table);
42 }
43 };
44
45
46 RomanCreator::RomanCreator(void)
47 : pimpl(new pImpl(RomanTable[0][0], ROMAN_CONVERT_SIZE_MAX)) {
48 }
49
50
51 RomanCreator::~RomanCreator(void) {
52 }
53
54
55 void RomanCreator::convert(std::vector<Uint16>& dst, const Uint16* input) {
56 pimpl->converted.clear();
57
58 // •ĎŠˇ•śŽš—ń‚đ‘ă“ü
59 size_t input_length = ustrlen(input);
60 for (size_t i = 0; i < input_length; ++i) {
61 pimpl->converted.push_back(input[i]);
62 }
63
64 int steps = pimpl->max_length * 2;
65 for (long i = static_cast<int>(pimpl->converted.size()) -1; i >= 0; --i) {
66 // ˆę’v‚ľ‚˝ƒpƒ^[ƒ“‚đ’uЎ‚ˇ‚é
67 for (int j = pimpl->max_length;
68 pimpl->convert_table[j] != 0x0; j += steps) {
69 int ptn_length = static_cast<int>(pimpl->ptnlen(j, pimpl->convert_table));
70 int compare_first = i - (ptn_length -1);
71 if (compare_first < 0) {
72 continue;
73 }
74 size_t match =
75 pimpl->converted.compare(compare_first, ptn_length,
76 &pimpl->convert_table[j]);
77 if (match == 0) {
78 pimpl->replace(compare_first, j);
79
80 // nba -> ‚ń‚΁A‚Ć‚˘‚Á‚˝•ĎŠˇ—p‚Ě‚˝‚߂ɁA‚P•śŽš•Ş–ß‚é
81 ++i;
82 break;
83 }
84 }
85 }
86 pimpl->converted.push_back(0x0);
87
88 pimpl->converted_char.clear();
89 for (size_t i = 0; i < pimpl->converted.size(); ++i) {
90 pimpl->converted_char.
91 push_back(static_cast<unsigned char>(pimpl->converted[i]));
92 }
93 dst = pimpl->converted_char;
94 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26