@ 240413.1

240208.1 · 03509a98a092b522b2ff0de13e53513d18b3b837

Fixed wrong width calculation for variation selectors combined with regular characters. Fixes #50

reading declarations

grapheme.go

@@ -253,16 +253,14 @@ func FirstGraphemeCluster(b []byte, state int) (cluster, rest []byte, width, new 			return b[:length], b[length:], width, state | (prop << shiftGraphemePropState) 		} -		if r == vs16 {-			width = 2-		} else if firstProp != prExtendedPictographic && firstProp != prRegionalIndicator && firstProp != prL {-			width += runeWidth(r, prop)-		} else if firstProp == prExtendedPictographic {+		if firstProp == prExtendedPictographic { 			if r == vs15 { 				width = 1-			} else {+			} else if r == vs16 { 				width = 2 			}+		} else if firstProp != prRegionalIndicator && firstProp != prL {+			width += runeWidth(r, prop) 		}  		length += l@@ -315,16 +313,14 @@ func FirstGraphemeClusterInString(str string, state int) (cluster, rest string, 			return str[:length], str[length:], width, state | (prop << shiftGraphemePropState) 		} -		if r == vs16 {-			width = 2-		} else if firstProp != prExtendedPictographic && firstProp != prRegionalIndicator && firstProp != prL {-			width += runeWidth(r, prop)-		} else if firstProp == prExtendedPictographic {+		if firstProp == prExtendedPictographic { 			if r == vs15 { 				width = 1-			} else {+			} else if r == vs16 { 				width = 2 			}+		} else if firstProp != prRegionalIndicator && firstProp != prL {+			width += runeWidth(r, prop) 		}  		length += l

step.go

@@ -150,16 +150,14 @@ func Step(b []byte, state int) (cluster, rest []byte, boundaries int, newState i 			return b[:length], b[length:], boundary, graphemeState | (wordState << shiftWordState) | (sentenceState << shiftSentenceState) | (lineState << shiftLineState) | (prop << shiftPropState) 		} -		if r == vs16 {-			width = 2-		} else if firstProp != prExtendedPictographic && firstProp != prRegionalIndicator && firstProp != prL {-			width += runeWidth(r, prop)-		} else if firstProp == prExtendedPictographic {+		if firstProp == prExtendedPictographic { 			if r == vs15 { 				width = 1-			} else {+			} else if r == vs16 { 				width = 2 			}+		} else if firstProp != prRegionalIndicator && firstProp != prL {+			width += runeWidth(r, prop) 		}  		length += l@@ -226,16 +224,14 @@ func StepString(str string, state int) (cluster, rest string, boundaries int, ne 			return str[:length], str[length:], boundary, graphemeState | (wordState << shiftWordState) | (sentenceState << shiftSentenceState) | (lineState << shiftLineState) | (prop << shiftPropState) 		} -		if r == vs16 {-			width = 2-		} else if firstProp != prExtendedPictographic && firstProp != prRegionalIndicator && firstProp != prL {-			width += runeWidth(r, prop)-		} else if firstProp == prExtendedPictographic {+		if firstProp == prExtendedPictographic { 			if r == vs15 { 				width = 1-			} else {+			} else if r == vs16 { 				width = 2 			}+		} else if firstProp != prRegionalIndicator && firstProp != prL {+			width += runeWidth(r, prop) 		}  		length += l

width_test.go

@@ -277,8 +277,8 @@ var widthTestCases = []struct { 	{"\u00a9\u061c", 1}, 	{"\u00a9\u000a", 1}, 	{"\u00a9\u000d", 1},-	{"\u00a9\u0300", 2}, // This is really 1 but we can't handle it.-	{"\u00a9\u200d", 2},+	{"\u00a9\u0300", 1},+	{"\u00a9\u200d", 1}, 	{"\u00a9a", 2}, 	{"\u00a9\u1b05", 2}, 	{"\u00a9\u2985", 2},@@ -341,7 +341,7 @@ var widthTestCases = []struct { 	{"\u263a\ufe0f", 2},                         // White smiling face (with variation selector 16 = emoji presentation) 	{"\u231b", 2},                               // Hourglass 	{"\u231b\ufe0e", 1},                         // Hourglass (with variation selector 15 = text presentation)-	{"1\ufe0f", 2},                              // Emoji presentation of digit one.+	{"1\ufe0f", 1},                              // Emoji presentation of digit one. }  // String width tests using the StringWidth function.