-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
201 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package trl | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
/* | ||
https://regexr.com/ | ||
https://pkg.go.dev/regexp#Regexp.FindAllStringIndex | ||
spaces some-path/to\directory whitespace | ||
([\s]* ([\S]* [\\/] [\S]*) [\s]*) | ||
condensed | ||
([\S]*[\\/][\S]*) | ||
*/ | ||
var pathToken = regexp.MustCompile(`[\S]*[\\/][\S]*`) | ||
var _ = pathToken.FindAllStringIndex(`word <div style='font-size:90%' alt="attr" >div content</div> for/ward -and- back\ward eol`, -1) | ||
|
||
// splitPaths returns [][]int{} | ||
func splitPaths(re *regexp.Regexp, s string) [][]int { | ||
return re.FindAllStringIndex(s, -1) | ||
} | ||
|
||
func recombine(s string, ps [][]int) string { | ||
w := &strings.Builder{} | ||
_ = w | ||
prev := 0 | ||
for i := 0; i < len(ps); i++ { | ||
occ := ps[i] | ||
fmt.Fprint(w, s[prev:occ[0]]) | ||
fmt.Fprint(w, s[occ[0]:occ[1]]) | ||
} | ||
return w.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package trl | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"reflect" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
var aAndPossiblyB = regexp.MustCompile(`ab?`) | ||
|
||
func Test_splitPaths(t *testing.T) { | ||
log.Printf("this test is temporary disabled") | ||
return | ||
|
||
type args struct { | ||
s string | ||
re *regexp.Regexp | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want1 [][]int | ||
want2 string | ||
}{ | ||
{ | ||
name: "t1", | ||
want1: [][]int{ | ||
{1, 3}, | ||
{10, 12}, | ||
{18, 19}, | ||
}, | ||
args: args{ | ||
// 012345678901234567890 | ||
// _ _ _ _ __ | ||
s: `tablett hablo espanol`, | ||
re: aAndPossiblyB, | ||
}, | ||
}, | ||
{ | ||
name: "t2", | ||
want1: [][]int{ | ||
{6, 14}, | ||
}, | ||
args: args{ | ||
// 01234567890123456789 | ||
// _ _ | ||
s: `start for/ward stop`, | ||
re: pathToken, | ||
}, | ||
}, | ||
{ | ||
name: "t3", | ||
want1: [][]int{ | ||
{48, 61}, | ||
{62, 70}, | ||
{77, 86}, | ||
}, | ||
args: args{ | ||
s: `word <div style='font-size:90%' alt="attr" >div content</div> for/ward -and- back\ward eol`, | ||
re: pathToken, | ||
}, | ||
}, | ||
} | ||
for idx, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
nm := tt.name | ||
if nm == "" { | ||
nm = fmt.Sprintf("t%v", idx) | ||
} | ||
got1 := splitPaths(tt.args.re, tt.args.s) | ||
if !reflect.DeepEqual(got1, tt.want1) { | ||
t.Errorf("%10s - splitPaths() = \n\t got %v\n\t want %v", | ||
nm, | ||
got1, | ||
tt.want1, | ||
) | ||
} else { | ||
// t.Logf("%10s - is fine - %v", nm, got1) | ||
} | ||
got2 := recombine(tt.args.s, got1) | ||
if !reflect.DeepEqual(got2, tt.args.s) { | ||
t.Errorf("%10s - recombine() = \n\t got %v\n\t want %v", | ||
nm, | ||
got2, | ||
tt.args.s, | ||
) | ||
} else { | ||
// t.Logf("%10s - recombined to %s", nm, got2) | ||
} | ||
}) | ||
} | ||
|
||
} |