aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DBCS.cxx28
-rw-r--r--src/DBCS.h3
2 files changed, 21 insertions, 10 deletions
diff --git a/src/DBCS.cxx b/src/DBCS.cxx
index f4aaff433..f92b7a5a9 100644
--- a/src/DBCS.cxx
+++ b/src/DBCS.cxx
@@ -7,8 +7,10 @@
#include <cstdint>
+#include <vector>
#include <array>
#include <map>
+#include <algorithm>
#include "DBCS.h"
@@ -99,21 +101,31 @@ bool IsDBCSValidSingleByte(int codePage, int ch) noexcept {
// NOLINTEND(*-magic-numbers)
-using CodePageToFoldMap = std::map<int, FoldMap>;
+namespace {
+
+struct CodePageFoldMap {
+ int codePage = 0;
+ FoldMap foldMap;
+ explicit CodePageFoldMap(int codePage_) noexcept : codePage {codePage_} {}
+};
+
+using CodePageToFoldMap = std::vector<CodePageFoldMap>;
CodePageToFoldMap cpToFoldMap;
-bool DBCSHasFoldMap(int codePage) {
- const CodePageToFoldMap::const_iterator it = cpToFoldMap.find(codePage);
- return it != cpToFoldMap.end();
}
-FoldMap *DBCSGetMutableFoldMap(int codePage) {
- // Constructs if needed
- return &cpToFoldMap[codePage];
+FoldMap *DBCSCreateFoldMap(int codePage) {
+ cpToFoldMap.emplace_back(codePage);
+ return &(cpToFoldMap.back().foldMap);
}
const FoldMap *DBCSGetFoldMap(int codePage) {
- return &cpToFoldMap[codePage];
+ const CodePageToFoldMap::iterator it = std::find_if(cpToFoldMap.begin(), cpToFoldMap.end(),
+ [codePage](const CodePageFoldMap &cpfm) -> bool {return cpfm.codePage == codePage; });
+ if (it != cpToFoldMap.end()) {
+ return &(it->foldMap);
+ }
+ return nullptr;
}
}
diff --git a/src/DBCS.h b/src/DBCS.h
index 2b66db261..466d70ec7 100644
--- a/src/DBCS.h
+++ b/src/DBCS.h
@@ -41,8 +41,7 @@ struct DBCSPair {
};
using FoldMap = std::array<DBCSPair, 0x8000>;
-bool DBCSHasFoldMap(int codePage);
-FoldMap *DBCSGetMutableFoldMap(int codePage);
+FoldMap *DBCSCreateFoldMap(int codePage);
const FoldMap *DBCSGetFoldMap(int codePage);
}