MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxUTF8Advance

Function fxUTF8Advance

modules/piu/PC/Code/piuCode.c:87–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85};
86
87int32_t fxUTF8Advance(xsStringValue string, int32_t offset, int32_t direction)
88{
89 uint8_t* text = (uint8_t*)string + offset;
90 if (direction >= 0) {
91 unsigned char aByte = (unsigned char)*text;
92 if (!(aByte & 0x80))
93 return 1;
94 if ((aByte & 0xe0) != 0xe0)
95 return 2;
96 if ((aByte & 0xf0) != 0xf0)
97 return 3;
98 if ((aByte & 0xf8) == 0xf0)
99 return 4;
100 }
101 else {
102 if ((text[-1] & 0xc0) == 0x80) {
103 if ((text[-2] & 0xc0) == 0x80) {
104 if ((text[-3] & 0xc0) == 0x80) {
105 if ((text[-4] & 0xc0) == 0x80)
106 return -4;
107 }
108 else
109 return -3;
110 }
111 else
112 return -2;
113 }
114 else
115 return -1;
116 }
117
118 return 0; // error
119}
120
121void PiuCodeBind(void* it, PiuApplication* application, PiuView* view)
122{

Callers 1

PiuCodeFindWordBreakFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected