@@ -9,53 +9,58 @@ import (
9
9
)
10
10
11
11
func EncodeEscapeChars (s string ) string {
12
- return strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (s , `\t` , `【\\ 】t` ), `\s` , `【\\ 】s` ), `\r` , `【\\ 】r` ), `\n` , `【\\ 】n` )
12
+ return strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (s , `\t` , `【& 】t` ), `\s` , `【& 】s` ), `\r` , `【& 】r` ), `\n` , `【& 】n` )
13
13
}
14
14
15
15
func DecodeEscapeChars (s string ) string {
16
- return strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (s , `【\ 】t` , `\t` ), `【\ 】s` , `\s` ), `【\ 】r` , `\r` ), `【\ 】n` , `\n` )
16
+ return strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (s , `【& 】t` , `\t` ), `【& 】s` , `\s` ), `【& 】r` , `\r` ), `【& 】n` , `\n` )
17
17
}
18
18
19
19
func FixReturn (s string ) string {
20
- s = strings .TrimSpace (s )
21
- if s == "" {
22
- return s
23
- }
24
20
25
21
var scene1 = regexp .MustCompile (`return\s+(\d+)\s+(\S+)\s*;` )
26
22
var scene2 = regexp .MustCompile (`return\s+(\d+)\s+"(\S+)"\s*;` )
27
23
var scene3 = regexp .MustCompile (`return\s+(\S+)\s*;` )
28
24
var scene4 = regexp .MustCompile (`return\s+"(\S+)"\s*;` )
29
25
var scene5 = regexp .MustCompile (`return\s+(\d+)\s*;` )
26
+ var scene6 = regexp .MustCompile (`return\s+"(.+)"\s*;` )
27
+ var scene7 = regexp .MustCompile (`return\s+(\d+)\s+"(.+)"\s*;` )
28
+ var scene8 = regexp .MustCompile (`return\s+(\d+)\s+"([\s|\S|\n|\r|\t]+)"\s*;` )
29
+ var scene9 = regexp .MustCompile (`return\s+"([\s|\S|\n|\r|\t]+)"\s*;` )
30
30
31
31
if scene1 .MatchString (s ) {
32
32
if scene2 .MatchString (s ) { // eg: `return 200 "ok";`
33
- s = scene2 .ReplaceAllString (s , "$1 \" $2\" " )
33
+ return strings . TrimSpace ( scene2 .ReplaceAllString (s , "return $1 \" $2\" ;" ) )
34
34
} else { // eg: `return 200 $content;`
35
- s = scene1 .ReplaceAllString (s , "$1 \" $2\" " )
35
+ return strings . TrimSpace ( scene1 .ReplaceAllString (s , "return $1 \" $2\" ;" ) )
36
36
}
37
37
} else if scene3 .MatchString (s ) {
38
- fmt .Println ("!!" )
39
38
if scene5 .MatchString (s ) { // eg: `return 200;`
40
- s = scene5 .ReplaceAllString (s , "$1" )
41
- } else if scene4 .MatchString (s ) { // eg: `return "ok";`
42
- fmt .Println ("!!!!!" , s )
43
-
44
- s = scene4 .ReplaceAllString (s , "\" $1\" " )
39
+ return strings .TrimSpace (scene5 .ReplaceAllString (s , "return $1;" ))
40
+ } else if scene6 .MatchString (s ) { // eg: `return "ok";`
41
+ if scene4 .MatchString (s ) {
42
+ return strings .TrimSpace (scene4 .ReplaceAllString (s , "return \" $1\" ;" ))
43
+ } else {
44
+ return strings .TrimSpace (scene6 .ReplaceAllString (s , "return \" $1\" ;" ))
45
+ }
45
46
} else { // eg: `return BACKEND\n;`
46
-
47
47
found := scene3 .FindString (s )
48
48
if ! (strings .HasPrefix (found , `"` ) && strings .HasSuffix (found , `"` )) {
49
- s = scene3 .ReplaceAllString (s , "$1" )
49
+ return strings . TrimSpace ( scene3 .ReplaceAllString (s , "return $1;" ) )
50
50
} else {
51
- s = scene3 .ReplaceAllString (s , "\" $1\" " )
51
+ return strings . TrimSpace ( scene3 .ReplaceAllString (s , "return \" $1\" ;" ) )
52
52
}
53
53
}
54
54
} else {
55
- fmt .Println ("---" , s )
56
-
55
+ if scene7 .MatchString (s ) {
56
+ return strings .TrimSpace (scene7 .ReplaceAllString (s , "return $1 \" $2\" ;" ))
57
+ } else if scene8 .MatchString (s ) {
58
+ return strings .TrimSpace (scene8 .ReplaceAllString (s , "return $1 \" $2\" ;" ))
59
+ } else if scene9 .MatchString (s ) {
60
+ return strings .TrimSpace (scene9 .ReplaceAllString (s , "return \" $1\" ;" ))
61
+ }
57
62
}
58
- return "return " + strings . TrimSpace ( s ) + ";"
63
+ return s
59
64
}
60
65
61
66
func FixVars (s string ) string {
0 commit comments