aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/DBCS.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-12-04 13:17:48 +1100
committerNeil <nyamatongwe@gmail.com>2025-12-04 13:17:48 +1100
commit3370ea39fa730ec22e4a2f5496729543c96cc98b (patch)
tree748af799dbc015e1ef5cd93818be9b12f0bc820f /src/DBCS.cxx
parent2f9129b86903d5f0756217fa719d7f1d894acebf (diff)
downloadscintilla-mirror-3370ea39fa730ec22e4a2f5496729543c96cc98b.tar.gz
Feature [feature-requests:#1564]. Use vector to store FoldMaps as map is not
nothrow default constructable.
Diffstat (limited to 'src/DBCS.cxx')
-rw-r--r--src/DBCS.cxx28
1 files changed, 20 insertions, 8 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;
}
}