Skip to content

Commit f094ebc

Browse files
committed
support for POSIX, root redirect
1 parent 3b3da3e commit f094ebc

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/regexplanet.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"regexp"
1111
"runtime"
1212
"strconv"
13-
// "strings"
1413
"time"
1514
)
1615

@@ -21,7 +20,7 @@ func init() {
2120
}
2221

2322
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)
2524
}
2625

2726
func write_with_callback(w http.ResponseWriter, callback string, v interface{}) {
@@ -135,6 +134,7 @@ func test_handler(w http.ResponseWriter, r *http.Request) {
135134
var strRegex = r.FormValue("regex")
136135
var replacement = r.FormValue("replacement")
137136
var callback = r.FormValue("callback")
137+
var options = r.Form["option"]
138138

139139
if strRegex == "" {
140140
write_with_callback(w, callback, TestResult{ false, "", "No regex to test"})
@@ -171,9 +171,28 @@ func test_handler(w http.ResponseWriter, r *http.Request) {
171171
buffer.WriteString("</code></td>\n");
172172
buffer.WriteString("\t\t</tr>\n");
173173

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);
177196
if err != nil {
178197
buffer.WriteString("\t\t<tr>\n");
179198
buffer.WriteString("\t\t\t<td>Error</td>\n");

0 commit comments

Comments
 (0)