-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlufz-check-phonetics.cc
65 lines (58 loc) · 1.32 KB
/
lufz-check-phonetics.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <ctype.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "lufz-utf8.h"
#include "lufz-util.h"
using namespace std;
using namespace lufz;
namespace {
void PrintChars(const std::string& s) {
printf("{%s}", s.c_str());
const std::vector<std::string> chars = LufzUTF8Chars(s);
for (const auto& c : chars) {
printf("(");
for (unsigned char b : c) {
printf("%02x", b);
}
printf(")");
}
printf("\n");
}
} // namespace
/**
* Reads stdin. Prints each char that it does not
* recognize as a Phonetics symbol (IPA/ARPAbet).
*/
int main(int argc, char* argv[]) {
LufzUtil util("Phonetics");
char buf[MAX_LINE_LENGTH];
while (fgets(buf, sizeof(buf), stdin)) {
std::string line(buf);
line = line.substr(0, line.length() - 1); // Remove trailing \n
std::vector<std::string> parts = util.PartsOf(line);
int i = 0;
while (i < parts.size()) {
std::string part = parts[i];
if (util.IsLetter(part)) {
i++;
continue;
}
int j = i + 1;
while (j < parts.size() && !util.IsLetter(parts[j])) {
part += parts[j];
j++;
}
PrintChars(part);
i = j;
}
}
return 0;
}