#include <fstream> #include <iostream> #include <vector> #include <unicode/ucnv.h> #include <unicode/regex.h> // 要リンク #pragma comment(lib, "icuuc.lib") //regex.hに必要 #pragma comment(lib, "icuin.lib") // 以下のdllを要求される // icudt69.dll // icuuc69.dll // icuin69.dll regexに必要 int main() { std::fstream w( "C:\\dev\\icu-test\\converted.txt", std::ios::out | std::ios::binary | std::ios::trunc); std::u16string u16s = u"aい山うkえ👨👧經お经"; icu::UnicodeString ustr(u16s.c_str()); UErrorCode status = U_ZERO_ERROR; icu::RegexMatcher matcher(u"[う-お].+[あ-お]", 0, status); matcher.reset(ustr);
if (matcher.find()) { icu::UnicodeString ret; int start = matcher.start(status); // string index of start of match. int end = matcher.end(status); ustr.extract( start, end - start, ret ); w.write((char*)ret.getBuffer(), ret.length()*2); } ///////////////////////////////// }