Skip to content

Commit 9936e75

Browse files
committed
Extend IsValid to match go
1 parent e2341c2 commit 9936e75

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

NStack/unicode/Rune.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ public Rune (char ch)
6262
}
6363

6464
/// <summary>
65-
/// Gets a value indicating whether this <see cref="T:System.Rune"/> contains a valid Unicode codepoint.
65+
/// Gets a value indicating whether this <see cref="T:System.Rune"/> can be encoded as UTF-8
6666
/// </summary>
6767
/// <value><c>true</c> if is valid; otherwise, <c>false</c>.</value>
68-
public bool IsValid => value <= MaxRune.value;
68+
public bool IsValid {
69+
get {
70+
if (0 <= value && value <= surrogateMin)
71+
return true;
72+
if (surrogateMax < value && value < MaxRune)
73+
return true;
74+
return false;
75+
}
76+
}
6977

7078
// Code points in the surrogate range are not valid for UTF-8.
7179
const uint surrogateMin = 0xd800;

0 commit comments

Comments
 (0)