diff options
author | Weixuan XIAO <veyx.shaw@gmail.com> | 2020-11-22 19:02:36 +0100 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2020-11-26 11:00:51 +0800 |
commit | 76108f9b60e521af2d716b22dd5dd99d62609e72 (patch) | |
tree | 235f28e9cde82a342cf47390e4eb3e079002cb76 /src | |
parent | f1e88a707de818277e937fb77d3d9c737e470377 (diff) | |
download | libpinyin-76108f9b60e521af2d716b22dd5dd99d62609e72.tar.gz libpinyin-76108f9b60e521af2d716b22dd5dd99d62609e72.tar.xz libpinyin-76108f9b60e521af2d716b22dd5dd99d62609e72.zip |
Fix delimiter for reading table files on macOS
On macOS under llvm/clang++, the default delimiter for format string is
weird: it cannot read full CJK characters from the table files.
This patch adds macOS-specified code to make "\t" and " " the implicit
delimiter.
Ref:
https://stackoverflow.com/questions/12885628/changing-the-scanf-delimiter
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/chewing_large_table.cpp | 5 | ||||
-rw-r--r-- | src/storage/chewing_large_table2.cpp | 5 | ||||
-rw-r--r-- | src/storage/phrase_index.cpp | 5 | ||||
-rw-r--r-- | src/storage/phrase_large_table2.cpp | 5 | ||||
-rw-r--r-- | src/storage/phrase_large_table3.cpp | 5 |
5 files changed, 25 insertions, 0 deletions
diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index 5716c5c..dccdc8e 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -669,8 +669,13 @@ bool ChewingLargeTable::load_text(FILE * infile, TABLE_PHONETIC_TYPE type) { size_t freq; while (!feof(infile)) { +#ifdef __APPLE__ + int num = fscanf(infile, "%255s %255[^ \t] %u %ld", + pinyin, phrase, &token, &freq); +#else int num = fscanf(infile, "%255s %255s %u %ld", pinyin, phrase, &token, &freq); +#endif if (4 != num) continue; diff --git a/src/storage/chewing_large_table2.cpp b/src/storage/chewing_large_table2.cpp index 194173b..0dc96f4 100644 --- a/src/storage/chewing_large_table2.cpp +++ b/src/storage/chewing_large_table2.cpp @@ -115,8 +115,13 @@ bool ChewingLargeTable2::load_text(FILE * infile, TABLE_PHONETIC_TYPE type) { size_t freq; while (!feof(infile)) { +#ifdef __APPLE__ + int num = fscanf(infile, "%255s %255[^ \t] %u %ld", + pinyin, phrase, &token, &freq); +#else int num = fscanf(infile, "%255s %255s %u %ld", pinyin, phrase, &token, &freq); +#endif if (4 != num) continue; diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp index 06b613f..36cb149 100644 --- a/src/storage/phrase_index.cpp +++ b/src/storage/phrase_index.cpp @@ -527,8 +527,13 @@ bool FacadePhraseIndex::load_text(guint8 phrase_index, FILE * infile, phrase_token_t cur_token = 0; while (!feof(infile)){ +#ifdef __APPLE__ + int num = fscanf(infile, "%255s %255[^ \t] %u %ld", + pinyin, phrase, &token, &freq); +#else int num = fscanf(infile, "%255s %255s %u %ld", pinyin, phrase, &token, &freq); +#endif if (4 != num) continue; diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp index 38dafb3..0e6fa62 100644 --- a/src/storage/phrase_large_table2.cpp +++ b/src/storage/phrase_large_table2.cpp @@ -472,8 +472,13 @@ bool PhraseLargeTable2::load_text(FILE * infile){ size_t freq; while (!feof(infile)) { +#ifdef __APPLE__ + int num = fscanf(infile, "%255s %255[^ \t] %u %ld", + pinyin, phrase, &token, &freq); +#else int num = fscanf(infile, "%255s %255s %u %ld", pinyin, phrase, &token, &freq); +#endif if (4 != num) continue; diff --git a/src/storage/phrase_large_table3.cpp b/src/storage/phrase_large_table3.cpp index 696c612..1e8fd76 100644 --- a/src/storage/phrase_large_table3.cpp +++ b/src/storage/phrase_large_table3.cpp @@ -128,8 +128,13 @@ bool PhraseLargeTable3::load_text(FILE * infile){ size_t freq; while (!feof(infile)) { +#ifdef __APPLE__ + int num = fscanf(infile, "%255s %255[^ \t] %u %ld", + pinyin, phrase, &token, &freq); +#else int num = fscanf(infile, "%255s %255s %u %ld", pinyin, phrase, &token, &freq); +#endif if (4 != num) continue; |