MCPcopy Create free account
hub / github.com/microsoft/typescript-go / decodeEntity

Function decodeEntity

internal/transformers/jsxtransforms/jsx.go:914–953  ·  view source on GitHub ↗
(entity string)

Source from the content-addressed store, hash-verified

912}
913
914func decodeEntity(entity string) (rune, bool) {
915 if len(entity) == 0 {
916 return 0, false
917 }
918
919 if entity[0] == '#' {
920 entity = entity[1:]
921 if len(entity) == 0 {
922 return 0, false
923 }
924
925 base := 10
926 if entity[0] == 'x' {
927 base = 16
928 entity = entity[1:]
929 }
930
931 if len(entity) == 0 {
932 return 0, false
933 }
934
935 for _, c := range entity {
936 if base == 16 && !stringutil.IsHexDigit(c) {
937 return 0, false
938 }
939 if base == 10 && !stringutil.IsDigit(c) {
940 return 0, false
941 }
942 }
943
944 parsed, err := strconv.ParseInt(entity, base, 32)
945 if err != nil {
946 return 0, false
947 }
948 return rune(parsed), true
949 }
950
951 r, ok := entities[entity]
952 return r, ok
953}
954
955var entities = map[string]rune{
956 "quot": 0x0022,

Callers 1

decodeEntitiesFunction · 0.85

Calls 3

IsHexDigitFunction · 0.92
IsDigitFunction · 0.92
lenFunction · 0.85

Tested by

no test coverage detected