Skip to content

Commit

Permalink
[YAML/TOML] Fix ISO-8601 timestamp parsing for east timezone, issue #672
Browse files Browse the repository at this point in the history
.
  • Loading branch information
zufuliu committed Jun 5, 2023
1 parent 2ec39dd commit 8f7f1d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions scintilla/lexers/LexTOML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ constexpr bool IsTOMLOperator(int ch) noexcept {
return AnyOf(ch, '[', ']', '{', '}', ',', '=', '.', '+', '-');
}

constexpr bool IsTOMLDateTime(int ch, int chNext) noexcept {
return ((ch == '-' || ch == ':' || ch == '.') && IsADigit(chNext))
|| (ch == ' ' && (chNext == '-' || IsADigit(chNext)));
}

constexpr bool IsTOMLUnquotedKey(int ch) noexcept {
return IsIdentifierChar(ch) || ch == '-';
}
Expand Down Expand Up @@ -124,7 +119,7 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt

case SCE_TOML_NUMBER:
if (!IsDecimalNumber(sc.chPrev, sc.ch, sc.chNext)) {
if (IsTOMLDateTime(sc.ch, sc.chNext)) {
if (IsISODateTime(sc.ch, sc.chNext)) {
sc.ChangeState(SCE_TOML_DATETIME);
} else if (IsTOMLKey(sc, braceCount, nullptr)) {
continue;
Expand All @@ -133,7 +128,7 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
break;

case SCE_TOML_DATETIME:
if (!(IsIdentifierChar(sc.ch) || IsTOMLDateTime(sc.ch, sc.chNext))) {
if (!(IsIdentifierChar(sc.ch) || IsISODateTime(sc.ch, sc.chNext))) {
if (IsTOMLKey(sc, braceCount, nullptr)) {
continue;
}
Expand Down
9 changes: 2 additions & 7 deletions scintilla/lexers/LexYAML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ constexpr bool IsYAMLAnchorChar(int ch) noexcept {
return IsGraphic(ch) && !IsYAMLFlowIndicator(ch);
}

constexpr bool IsYAMLDateTime(int ch, int chNext) noexcept {
return ((ch == '-' || ch == ':' || ch == '.') && IsADigit(chNext))
|| (ch == ' ' && (chNext == '-' || IsADigit(chNext)));
}

bool IsYAMLText(StyleContext& sc, int braceCount, const WordList *kwList) {
const int state = sc.state;
const Sci_Position endPos = braceCount? sc.styler.Length() : sc.lineStartNext;
Expand Down Expand Up @@ -216,7 +211,7 @@ void ColouriseYAMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt

case SCE_YAML_NUMBER:
if (!IsDecimalNumber(sc.chPrev, sc.ch, sc.chNext)) {
if (IsYAMLDateTime(sc.ch, sc.chNext)) {
if (IsISODateTime(sc.ch, sc.chNext)) {
sc.ChangeState(SCE_YAML_DATETIME);
} else if (IsYAMLText(sc, braceCount, nullptr)) {
continue;
Expand All @@ -225,7 +220,7 @@ void ColouriseYAMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
break;

case SCE_YAML_DATETIME:
if (!(IsIdentifierChar(sc.ch) || IsYAMLDateTime(sc.ch, sc.chNext))) {
if (!(IsIdentifierChar(sc.ch) || IsISODateTime(sc.ch, sc.chNext))) {
if (IsYAMLText(sc, braceCount, nullptr)) {
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions scintilla/lexlib/CharacterSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ constexpr bool IsFloatExponent(int chPrev, int ch, int chNext) noexcept {
&& (ch == '+' || ch == '-') && IsADigit(chNext);
}

constexpr bool IsISODateTime(int ch, int chNext) noexcept {
return ((ch == '+' || ch == '-' || ch == ':' || ch == '.') && IsADigit(chNext))
|| (ch == ' ' && (chNext == '-' || IsADigit(chNext)));
}

//[[deprecated]]
//constexpr bool IsASCII(int ch) noexcept {
// return ch >= 0 && ch < 0x80;
Expand Down

0 comments on commit 8f7f1d5

Please sign in to comment.