mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat(config): support for 5 code point glyphs in export
relates to https://github.com/ryanoasis/nerd-fonts/issues/365#issuecomment-1398110379
This commit is contained in:
parent
1a1aecbd36
commit
6fe030fd44
|
@ -235,13 +235,54 @@ func (cfg *Config) backup() {
|
|||
}
|
||||
|
||||
func escapeGlyphs(s string) string {
|
||||
shouldExclude := func(r rune) bool {
|
||||
if r < 0x1000 { // Basic Multilingual Plane
|
||||
return true
|
||||
}
|
||||
if r > 0x1F600 && r < 0x1F64F { // Emoticons
|
||||
return true
|
||||
}
|
||||
if r > 0x1F300 && r < 0x1F5FF { // Misc Symbols and Pictographs
|
||||
return true
|
||||
}
|
||||
if r > 0x1F680 && r < 0x1F6FF { // Transport and Map
|
||||
return true
|
||||
}
|
||||
if r > 0x2600 && r < 0x26FF { // Misc symbols
|
||||
return true
|
||||
}
|
||||
if r > 0x2700 && r < 0x27BF { // Dingbats
|
||||
return true
|
||||
}
|
||||
if r > 0xFE00 && r < 0xFE0F { // Variation Selectors
|
||||
return true
|
||||
}
|
||||
if r > 0x1F900 && r < 0x1F9FF { // Supplemental Symbols and Pictographs
|
||||
return true
|
||||
}
|
||||
if r > 0x1F1E6 && r < 0x1F1FF { // Flags
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var builder strings.Builder
|
||||
for _, r := range s {
|
||||
// exclude regular characters and emoji
|
||||
if r < 0x1000 || r > 0x10000 {
|
||||
// exclude regular characters and emojis
|
||||
if shouldExclude(r) {
|
||||
builder.WriteRune(r)
|
||||
continue
|
||||
}
|
||||
|
||||
if r > 0x10000 {
|
||||
// calculate surrogate pairs
|
||||
one := 0xd800 + (((r - 0x10000) >> 10) & 0x3ff)
|
||||
two := 0xdc00 + ((r - 0x10000) & 0x3ff)
|
||||
quoted := fmt.Sprintf("\\u%04x\\u%04x", one, two)
|
||||
builder.WriteString(quoted)
|
||||
continue
|
||||
}
|
||||
|
||||
quoted := fmt.Sprintf("\\u%04x", r)
|
||||
builder.WriteString(quoted)
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ func TestEscapeGlyphs(t *testing.T) {
|
|||
Input string
|
||||
Expected string
|
||||
}{
|
||||
{Input: "", Expected: "\\udb80\\ude4b"},
|
||||
{Input: "a", Expected: "a"},
|
||||
{Input: "\ue0b4", Expected: "\\ue0b4"},
|
||||
{Input: "\ufd03", Expected: "\\ufd03"},
|
||||
|
|
Loading…
Reference in a new issue