Skip to content

Commit

Permalink
std/jule/constant/lit: optimize escape sequence handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 23, 2025
1 parent 5a6a6aa commit 76aac63
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions std/jule/constant/lit/bytes.jule
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.

use "std/conv"
use "std/internal/byteslite"
use "std/unicode/utf8"
use "std/unsafe"

Expand Down Expand Up @@ -54,17 +55,9 @@ fn ToStr(mut lit: str): (str, errors: []Error) {
if len(lit) == 2 {
ret "", nil
}

// Means string is just ASCII text without escape sequences.
mut isPure := true
for _, r in lit {
if r >= utf8::RuneSelf || r == '\\' {
isPure = false
break
}
}

if isPure {
// If no escape sequence used, return the string directly with no quotes.
escapeseq := byteslite::IndexByteStr(lit, '\\') >= 0
if escapeseq {
ret lit[1 : len(lit)-1], nil
}

Expand Down

0 comments on commit 76aac63

Please sign in to comment.