Merge branch 'development' into development_actions007
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
module texttools
|
||||
module texttools
|
||||
|
||||
pub fn snake_case(s string) string {
|
||||
return separate_words(s).join('_')
|
||||
@@ -22,7 +22,7 @@ const separators = ['.', '_', '-', '/', ' ', ':', ',', ';']
|
||||
fn separate_words(s string) []string {
|
||||
mut words := []string{}
|
||||
mut word := ''
|
||||
for i, c in s {
|
||||
for _, c in s {
|
||||
if (c.is_capital() || c.ascii_str() in separators) && word != '' {
|
||||
words << word.to_lower()
|
||||
word = ''
|
||||
@@ -35,4 +35,4 @@ fn separate_words(s string) []string {
|
||||
words << word.to_lower()
|
||||
}
|
||||
return words
|
||||
}
|
||||
}
|
||||
@@ -84,44 +84,9 @@ pub fn name_fix_no_underscore(name string) string {
|
||||
return x
|
||||
}
|
||||
|
||||
pub fn name_fix_snake_to_pascal(name string) string {
|
||||
x := name.replace('_', ' ')
|
||||
p := x.title().replace(' ', '')
|
||||
return p
|
||||
}
|
||||
|
||||
pub fn name_fix_dot_notation_to_pascal(name string) string {
|
||||
x := name.replace('.', ' ')
|
||||
p := x.title().replace(' ', '')
|
||||
return p
|
||||
}
|
||||
|
||||
pub fn name_fix_pascal(name string) string {
|
||||
name_ := name_fix_snake_to_pascal(name)
|
||||
return name_fix_dot_notation_to_pascal(name_)
|
||||
}
|
||||
|
||||
pub fn name_fix_pascal_to_snake(name string) string {
|
||||
mut fixed := ''
|
||||
for i, c in name {
|
||||
if c.is_capital() && i != 0 {
|
||||
fixed += '_'
|
||||
}
|
||||
fixed += c.ascii_str()
|
||||
}
|
||||
return fixed.to_lower()
|
||||
}
|
||||
|
||||
pub fn name_fix_dot_notation_to_snake_case(name string) string {
|
||||
return name.replace('.', '_')
|
||||
}
|
||||
|
||||
// normalize a file path while preserving path structure
|
||||
pub fn path_fix(path_ string) string {
|
||||
if path_.len == 0 {
|
||||
return ''
|
||||
}
|
||||
return "${path_.trim('/')}"
|
||||
// remove underscores and extension
|
||||
pub fn name_fix_no_underscore_no_ext(name_ string) string {
|
||||
return name_fix_keepext(name_).all_before_last('.').replace('_', '')
|
||||
}
|
||||
|
||||
// normalize a file path while preserving path structure
|
||||
|
||||
@@ -41,7 +41,7 @@ The TextTools module provides a comprehensive set of utilities for text manipula
|
||||
- `name_fix_keepspace(name string) !string` - Like name_fix but preserves spaces
|
||||
- `name_fix_no_ext(name_ string) string` - Removes file extension
|
||||
- `name_fix_snake_to_pascal(name string) string` - Converts snake_case to PascalCase
|
||||
- `name_fix_pascal_to_snake(name string) string` - Converts PascalCase to snake_case
|
||||
- `snake_case(name string) string` - Converts PascalCase to snake_case
|
||||
- `name_split(name string) !(string, string)` - Splits name into site and page components
|
||||
|
||||
### Text Splitting
|
||||
@@ -103,7 +103,7 @@ text := texttools.dedent(" line1\n line2")
|
||||
### Name Processing
|
||||
```v
|
||||
// Convert to snake case
|
||||
name := texttools.name_fix_pascal_to_snake("HelloWorld")
|
||||
name := texttools.snake_case("HelloWorld")
|
||||
// Result: "hello_world"
|
||||
|
||||
// Convert to pascal case
|
||||
|
||||
Reference in New Issue
Block a user