>> 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
|
||||
DoHelp bool
|
||||
DoVersion bool
|
||||
Rset runeset
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -74,6 +75,15 @@ var FAT_RUNESET = runeset{
|
|||
{ 0x7d, MAX_CODE_POINT},
|
||||
}
|
||||
|
||||
var POSIX_PORTABLE_RUNESET = runeset{
|
||||
{ 0x2d, 0x2d },
|
||||
{ 0x2e, 0x2e },
|
||||
{ 0x5f, 0x5f },
|
||||
{ 0x30, 0x39 },
|
||||
{ 0x41, 0x5a },
|
||||
{ 0x61, 0x7a },
|
||||
}
|
||||
|
||||
/// MAIN FUNCTIONS
|
||||
/**
|
||||
* 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 {
|
||||
for _, runeRange := range FAT_RUNESET {
|
||||
func inRuneset(r rune, rset runeset) bool {
|
||||
for _, runeRange := range rset {
|
||||
if runeRange[0] <= r && r <= runeRange[1] {
|
||||
return true
|
||||
}
|
||||
|
|
@ -159,13 +169,13 @@ func (ctx *context) restrictRuneset(s string) string {
|
|||
toValidSubs := make(map[rune]string)
|
||||
if ctx.Strategy == "remove" {
|
||||
for _, r := range result {
|
||||
if !isFatValid(r) {
|
||||
if !inRuneset(r, ctx.Rset) {
|
||||
toValidSubs[r] = ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, r := range result {
|
||||
if !isFatValid(r) {
|
||||
if !inRuneset(r, ctx.Rset) {
|
||||
toValidSubs[r] = fmt.Sprintf("_U%X_", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -200,6 +210,7 @@ func parseCLIArgs(args []string) (context, error) {
|
|||
Strategy: "represent",
|
||||
DoHelp: false,
|
||||
DoVersion: false,
|
||||
Rset: FAT_RUNESET,
|
||||
}
|
||||
index := 1
|
||||
isFlag := func(arg string) bool {
|
||||
|
|
@ -215,6 +226,8 @@ func parseCLIArgs(args []string) (context, error) {
|
|||
case "-s", "--strategy":
|
||||
index++
|
||||
result.Strategy = args[index]
|
||||
case "-p", "--portable":
|
||||
result.Rset = POSIX_PORTABLE_RUNESET
|
||||
case "-h", "--help":
|
||||
result.DoHelp = true
|
||||
case "-v", "--version":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue