@@ -10,7 +10,6 @@ import (
10
10
"regexp"
11
11
"runtime"
12
12
"strconv"
13
- // "strings"
14
13
"time"
15
14
)
16
15
@@ -21,7 +20,7 @@ func init() {
21
20
}
22
21
23
22
func root_handler (w http.ResponseWriter , r * http.Request ) {
24
- fmt . Fprint (w , "Hello, RegexPlanet!" )
23
+ http . Redirect (w , r , "http://www.regexplanet.com/advanced/golang/index.html" , http . StatusFound )
25
24
}
26
25
27
26
func write_with_callback (w http.ResponseWriter , callback string , v interface {}) {
@@ -135,6 +134,7 @@ func test_handler(w http.ResponseWriter, r *http.Request) {
135
134
var strRegex = r .FormValue ("regex" )
136
135
var replacement = r .FormValue ("replacement" )
137
136
var callback = r .FormValue ("callback" )
137
+ var options = r .Form ["option" ]
138
138
139
139
if strRegex == "" {
140
140
write_with_callback (w , callback , TestResult { false , "" , "No regex to test" })
@@ -171,9 +171,28 @@ func test_handler(w http.ResponseWriter, r *http.Request) {
171
171
buffer .WriteString ("</code></td>\n " );
172
172
buffer .WriteString ("\t \t </tr>\n " );
173
173
174
- var re * regexp.Regexp
175
- var err error ;
176
- re , err = regexp .Compile (strRegex )
174
+ ifPosix := false ;
175
+
176
+ if len (options ) > 0 {
177
+ for loop := 0 ; loop < len (options ); loop ++ {
178
+ if options [loop ] == "posix" {
179
+ ifPosix = true ;
180
+ }
181
+ }
182
+ }
183
+
184
+ buffer .WriteString ("\t \t <tr>\n " );
185
+ buffer .WriteString ("\t \t \t <td>Option</td>\n " );
186
+ buffer .WriteString ("\t \t \t <td><code>" );
187
+ if (ifPosix ) {
188
+ buffer .WriteString (html .EscapeString ("CompilePOSIX()" ));
189
+ } else {
190
+ buffer .WriteString (html .EscapeString ("Compile()" ));
191
+ }
192
+ buffer .WriteString ("</code></td>\n " );
193
+ buffer .WriteString ("\t \t </tr>\n " );
194
+
195
+ re , err := regexp .Compile (strRegex );
177
196
if err != nil {
178
197
buffer .WriteString ("\t \t <tr>\n " );
179
198
buffer .WriteString ("\t \t \t <td>Error</td>\n " );
0 commit comments