|
|
|
|
|
|
using Unity.UIWidgets.ui; |
|
|
|
|
|
|
|
namespace Unity.UIWidgets.service { |
|
|
|
public class TextRange : IEquatable<TextRange> { |
|
|
|
public readonly int start; |
|
|
|
public readonly int end; |
|
|
|
|
|
|
|
public static TextRange collapsed(int offset) { |
|
|
|
D.assert(offset >= -1); |
|
|
|
return new TextRange(offset, offset); |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly TextRange empty = new TextRange(-1, -1); |
|
|
|
|
|
|
|
public TextRange(int start, int end) { |
|
|
|
D.assert(start >= -1); |
|
|
|
D.assert(end >= -1); |
|
|
|
this.start = start; |
|
|
|
this.end = end; |
|
|
|
} |
|
|
|
|
|
|
|
public bool isValid { |
|
|
|
get { return start >= 0 && end >= 0; } |
|
|
|
} |
|
|
|
|
|
|
|
public bool isCollapsed { |
|
|
|
get { return start == end; } |
|
|
|
} |
|
|
|
|
|
|
|
public bool isNormalized { |
|
|
|
get { return start <= end; } |
|
|
|
} |
|
|
|
|
|
|
|
public string textBefore(string text) { |
|
|
|
D.assert(isNormalized); |
|
|
|
return text.Substring(0, start); |
|
|
|
} |
|
|
|
|
|
|
|
public string textAfter(string text) { |
|
|
|
D.assert(isNormalized); |
|
|
|
return text.Substring(end); |
|
|
|
} |
|
|
|
|
|
|
|
public string textInside(string text) { |
|
|
|
D.assert(isNormalized); |
|
|
|
return text.Substring(start, end - start); |
|
|
|
} |
|
|
|
|
|
|
|
public bool Equals(TextRange other) { |
|
|
|
if (ReferenceEquals(null, other)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (ReferenceEquals(this, other)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return start == other.start && end == other.end; |
|
|
|
} |
|
|
|
|
|
|
|
public override bool Equals(object obj) { |
|
|
|
if (ReferenceEquals(null, obj)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (ReferenceEquals(this, obj)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (obj.GetType() != GetType()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return Equals((TextRange) obj); |
|
|
|
} |
|
|
|
|
|
|
|
public override int GetHashCode() { |
|
|
|
unchecked { |
|
|
|
return (start * 397) ^ end; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static bool operator ==(TextRange left, TextRange right) { |
|
|
|
return Equals(left, right); |
|
|
|
} |
|
|
|
|
|
|
|
public static bool operator !=(TextRange left, TextRange right) { |
|
|
|
return !Equals(left, right); |
|
|
|
} |
|
|
|
|
|
|
|
public override string ToString() { |
|
|
|
return $"TextRange Start: {start}, End: {end}"; |
|
|
|
} |
|
|
|
} |
|
|
|
// public class TextRange : IEquatable<TextRange> {
|
|
|
|
// public readonly int start;
|
|
|
|
// public readonly int end;
|
|
|
|
//
|
|
|
|
// public static TextRange collapsed(int offset) {
|
|
|
|
// D.assert(offset >= -1);
|
|
|
|
// return new TextRange(offset, offset);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public static readonly TextRange empty = new TextRange(-1, -1);
|
|
|
|
//
|
|
|
|
// public TextRange(int start, int end) {
|
|
|
|
// D.assert(start >= -1);
|
|
|
|
// D.assert(end >= -1);
|
|
|
|
// this.start = start;
|
|
|
|
// this.end = end;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public bool isValid {
|
|
|
|
// get { return start >= 0 && end >= 0; }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public bool isCollapsed {
|
|
|
|
// get { return start == end; }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public bool isNormalized {
|
|
|
|
// get { return start <= end; }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public string textBefore(string text) {
|
|
|
|
// D.assert(isNormalized);
|
|
|
|
// return text.Substring(0, start);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public string textAfter(string text) {
|
|
|
|
// D.assert(isNormalized);
|
|
|
|
// return text.Substring(end);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public string textInside(string text) {
|
|
|
|
// D.assert(isNormalized);
|
|
|
|
// return text.Substring(start, end - start);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public bool Equals(TextRange other) {
|
|
|
|
// if (ReferenceEquals(null, other)) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (ReferenceEquals(this, other)) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return start == other.start && end == other.end;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public override bool Equals(object obj) {
|
|
|
|
// if (ReferenceEquals(null, obj)) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (ReferenceEquals(this, obj)) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (obj.GetType() != GetType()) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return Equals((TextRange) obj);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public override int GetHashCode() {
|
|
|
|
// unchecked {
|
|
|
|
// return (start * 397) ^ end;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public static bool operator ==(TextRange left, TextRange right) {
|
|
|
|
// return Equals(left, right);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public static bool operator !=(TextRange left, TextRange right) {
|
|
|
|
// return !Equals(left, right);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public override string ToString() {
|
|
|
|
// return $"TextRange Start: {start}, End: {end}";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
public class TextSelection : TextRange, IEquatable<TextSelection> { |
|
|
|
public readonly int baseOffset; |
|
|
|