>> add support for POSIX portable runeset
This commit is contained in:
parent
b8375fb83e
commit
6a0425cafe
1 changed files with 17 additions and 4 deletions
21
main.go
21
main.go
|
|
@ -47,6 +47,7 @@ type context struct {
|
||||||
Strategy string
|
Strategy string
|
||||||
DoHelp bool
|
DoHelp bool
|
||||||
DoVersion bool
|
DoVersion bool
|
||||||
|
Rset runeset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -74,6 +75,15 @@ var FAT_RUNESET = runeset{
|
||||||
{ 0x7d, MAX_CODE_POINT},
|
{ 0x7d, MAX_CODE_POINT},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var POSIX_PORTABLE_RUNESET = runeset{
|
||||||
|
{ 0x2d, 0x2d },
|
||||||
|
{ 0x2e, 0x2e },
|
||||||
|
{ 0x5f, 0x5f },
|
||||||
|
{ 0x30, 0x39 },
|
||||||
|
{ 0x41, 0x5a },
|
||||||
|
{ 0x61, 0x7a },
|
||||||
|
}
|
||||||
|
|
||||||
/// MAIN FUNCTIONS
|
/// MAIN FUNCTIONS
|
||||||
/**
|
/**
|
||||||
* Compares paths so that all files come before the directories that contain
|
* Compares paths so that all files come before the directories that contain
|
||||||
|
|
@ -145,8 +155,8 @@ func (ctx *context) parseFileList() ([]string, map[string]bool, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isFatValid(r rune) bool {
|
func inRuneset(r rune, rset runeset) bool {
|
||||||
for _, runeRange := range FAT_RUNESET {
|
for _, runeRange := range rset {
|
||||||
if runeRange[0] <= r && r <= runeRange[1] {
|
if runeRange[0] <= r && r <= runeRange[1] {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -159,13 +169,13 @@ func (ctx *context) restrictRuneset(s string) string {
|
||||||
toValidSubs := make(map[rune]string)
|
toValidSubs := make(map[rune]string)
|
||||||
if ctx.Strategy == "remove" {
|
if ctx.Strategy == "remove" {
|
||||||
for _, r := range result {
|
for _, r := range result {
|
||||||
if !isFatValid(r) {
|
if !inRuneset(r, ctx.Rset) {
|
||||||
toValidSubs[r] = ""
|
toValidSubs[r] = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, r := range result {
|
for _, r := range result {
|
||||||
if !isFatValid(r) {
|
if !inRuneset(r, ctx.Rset) {
|
||||||
toValidSubs[r] = fmt.Sprintf("_U%X_", r)
|
toValidSubs[r] = fmt.Sprintf("_U%X_", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -200,6 +210,7 @@ func parseCLIArgs(args []string) (context, error) {
|
||||||
Strategy: "represent",
|
Strategy: "represent",
|
||||||
DoHelp: false,
|
DoHelp: false,
|
||||||
DoVersion: false,
|
DoVersion: false,
|
||||||
|
Rset: FAT_RUNESET,
|
||||||
}
|
}
|
||||||
index := 1
|
index := 1
|
||||||
isFlag := func(arg string) bool {
|
isFlag := func(arg string) bool {
|
||||||
|
|
@ -215,6 +226,8 @@ func parseCLIArgs(args []string) (context, error) {
|
||||||
case "-s", "--strategy":
|
case "-s", "--strategy":
|
||||||
index++
|
index++
|
||||||
result.Strategy = args[index]
|
result.Strategy = args[index]
|
||||||
|
case "-p", "--portable":
|
||||||
|
result.Rset = POSIX_PORTABLE_RUNESET
|
||||||
case "-h", "--help":
|
case "-h", "--help":
|
||||||
result.DoHelp = true
|
result.DoHelp = true
|
||||||
case "-v", "--version":
|
case "-v", "--version":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue