Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
create efficient string escape sequence block in simple.core.String. …
Browse files Browse the repository at this point in the history
…Test in examples/more/unescape_str.sim
  • Loading branch information
Thecarisma committed Apr 10, 2019
1 parent d2b3df2 commit 63a269e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
7 changes: 7 additions & 0 deletions examples/more/unescape_str.sim
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 10,11 @@ call simple.core.String

block main()
str = unEscapeString("Hello\tWorld\n")
display(str)
str = escapeString(str)
display(str)

str = unEscapeString("Hello\tWorld\nThis \t is it \n")
display(str)
str = escapeString(str)
display(str)
23 changes: 5 additions & 18 deletions modules/simple/core/String.sim
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 140,13 @@ block unEscapeString(string str)
newStr = ascii(13)
case 't'
newStr = ascii(09)
case 'v'
newStr = ascii(11)
case 'u'
uchar = [hexDigit(), hexDigit(), hexDigit(), hexDigit()]
newStr = ascii((uchar[0] << 12) | (uchar[1] << 8) | (uchar[2] << 4) | (uchar[3]))
default
throw(self, "Syntax Error : Illegal escape sequence in string escape sequence : " str[a])
throw("simple.core:unEscapeString", "Syntax Error : Illegal escape sequence in string escape sequence : " str[a])
return null
}
default
Expand All @@ -154,23 156,6 @@ block unEscapeString(string str)
}
return newStr

#look into JsonParser for escaping string
block uneEscapeString(val)
val = replaceStr(val, "\a", ascii(07))
val = replaceStr(val, "\007", ascii(07))
val = replaceStr(val, "\b", ascii(08))
val = replaceStr(val, "\f", ascii(12))
val = replaceStr(val, "\n", ascii(10))
val = replaceStr(val, "\r", ascii(13))
#val = replaceStr(val, "\t", ascii(09))
val = replaceStr(val, "\v", ascii(11))
val = replaceStr(val, "\\", ascii(92))
val = replaceStr(val, "\'", ascii(27))
val = replaceStr(val, '\"', ascii(22))
val = replaceStr(val, '\?', ascii(63))
#val = replaceStr(val, '\e', ascii(27))
return val

/*

*/
Expand All @@ -194,6 179,8 @@ block escapeString(string str)
nStr = "\t"
case 08
nStr = "\b"
case 11
nStr = "\v"
case 12
nStr = "\f"
default
Expand Down

0 comments on commit 63a269e

Please sign in to comment.