MCPcopy Create free account
hub / github.com/UI5/webcomponents / utf8Slice

Function utf8Slice

packages/main/test/pages/diffable-html.js:1020–1091  ·  view source on GitHub ↗
(buf, start, end)

Source from the content-addressed store, hash-verified

1018 }
1019
1020 function utf8Slice (buf, start, end) {
1021 end = Math.min(buf.length, end)
1022 var res = []
1023
1024 var i = start
1025 while (i < end) {
1026 var firstByte = buf[i]
1027 var codePoint = null
1028 var bytesPerSequence = (firstByte > 0xEF) ? 4
1029 : (firstByte > 0xDF) ? 3
1030 : (firstByte > 0xBF) ? 2
1031 : 1
1032
1033 if (i + bytesPerSequence <= end) {
1034 var secondByte, thirdByte, fourthByte, tempCodePoint
1035
1036 switch (bytesPerSequence) {
1037 case 1:
1038 if (firstByte < 0x80) {
1039 codePoint = firstByte
1040 }
1041 break
1042 case 2:
1043 secondByte = buf[i + 1]
1044 if ((secondByte & 0xC0) === 0x80) {
1045 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
1046 if (tempCodePoint > 0x7F) {
1047 codePoint = tempCodePoint
1048 }
1049 }
1050 break
1051 case 3:
1052 secondByte = buf[i + 1]
1053 thirdByte = buf[i + 2]
1054 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1055 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
1056 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1057 codePoint = tempCodePoint
1058 }
1059 }
1060 break
1061 case 4:
1062 secondByte = buf[i + 1]
1063 thirdByte = buf[i + 2]
1064 fourthByte = buf[i + 3]
1065 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1066 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
1067 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1068 codePoint = tempCodePoint
1069 }
1070 }
1071 }
1072 }
1073
1074 if (codePoint === null) {
1075 // we did not generate a valid codePoint so insert a
1076 // replacement char (U+FFFD) and advance only 1 byte
1077 codePoint = 0xFFFD

Callers 2

slowToStringFunction · 0.85
diffable-html.jsFile · 0.85

Calls 2

decodeCodePointsArrayFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…