forked from tcsh-org/tcsh
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace ugly utf8 cache with wrapper around c++ unordered_maps.
- Loading branch information
1 parent
7a568a1
commit 79a14db
Showing
3 changed files
with
46 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <unordered_map> | ||
#include <sh.h> | ||
|
||
static std::unordered_map<uint32_t,Char> utf8_chars; | ||
static std::unordered_map<Char,uint32_t> reverse_map; | ||
|
||
static Char currentIndex; | ||
extern "C" Char get_or_cache_utf8_mb(uint32_t inChar) { | ||
auto iter = utf8_chars.find(inChar); | ||
if(iter == utf8_chars.end()) { | ||
auto ret = utf8_chars.insert({inChar,currentIndex}); | ||
currentIndex++; | ||
if(currentIndex == LITERAL ) { | ||
currentIndex++; | ||
} | ||
if (ret.second) { | ||
reverse_map.insert({ret.first->second,inChar}); | ||
return ret.first->second; | ||
} | ||
return 0; | ||
} | ||
else { | ||
return iter->second; | ||
} | ||
} | ||
extern "C" uint32_t get_cached_utf8_mb(Char index) { | ||
|
||
auto iter = reverse_map.find(index); | ||
if(iter == reverse_map.end()) { | ||
return 0x00e29aa0; //"\U+26A0", Warning sign | ||
} | ||
return iter->second; | ||
} | ||
|