@@ -17,7 +17,6 @@ import (
17
17
"hash/crc32"
18
18
"html"
19
19
"io"
20
- "io/ioutil"
21
20
"math"
22
21
"math/big"
23
22
"math/rand"
@@ -34,6 +33,9 @@ import (
34
33
"time"
35
34
"unicode"
36
35
"unicode/utf8"
36
+
37
+ "golang.org/x/text/cases"
38
+ "golang.org/x/text/language"
37
39
)
38
40
39
41
//////////// Date/Time Functions ////////////
@@ -206,12 +208,15 @@ func Lcfirst(str string) string {
206
208
207
209
// Ucwords ucwords()
208
210
func Ucwords (str string ) string {
209
- return strings .Title (str )
211
+ caser := cases .Title (language .English )
212
+ titleStr := caser .String (str )
213
+
214
+ return titleStr
210
215
}
211
216
212
217
// Substr substr()
213
218
func Substr (str string , start uint , length int ) string {
214
- if start < 0 || length < - 1 {
219
+ if length < - 1 {
215
220
return str
216
221
}
217
222
switch {
@@ -774,7 +779,7 @@ func Md5File(path string) (string, error) {
774
779
hash := md5 .New ()
775
780
776
781
if fi .Size () < size {
777
- data , err := ioutil .ReadFile (path )
782
+ data , err := os .ReadFile (path )
778
783
if err != nil {
779
784
return "" , err
780
785
}
@@ -803,7 +808,7 @@ func Sha1(str string) string {
803
808
804
809
// Sha1File sha1_file()
805
810
func Sha1File (path string ) (string , error ) {
806
- data , err := ioutil .ReadFile (path )
811
+ data , err := os .ReadFile (path )
807
812
if err != nil {
808
813
return "" , err
809
814
}
@@ -1486,7 +1491,7 @@ func Pathinfo(path string, options int) map[string]string {
1486
1491
if ((options & 4 ) == 4 ) || ((options & 8 ) == 8 ) {
1487
1492
basename := ""
1488
1493
if (options & 2 ) == 2 {
1489
- basename , _ = info ["basename" ]
1494
+ basename = info ["basename" ]
1490
1495
} else {
1491
1496
basename = filepath .Base (path )
1492
1497
}
@@ -1520,11 +1525,11 @@ func FileExists(filename string) bool {
1520
1525
1521
1526
// IsFile is_file()
1522
1527
func IsFile (filename string ) bool {
1523
- _ , err := os .Stat (filename )
1528
+ fd , err := os .Stat (filename )
1524
1529
if err != nil && os .IsNotExist (err ) {
1525
1530
return false
1526
1531
}
1527
- return true
1532
+ return ! fd . IsDir ()
1528
1533
}
1529
1534
1530
1535
// IsDir is_dir()
@@ -1548,12 +1553,12 @@ func FileSize(filename string) (int64, error) {
1548
1553
1549
1554
// FilePutContents file_put_contents()
1550
1555
func FilePutContents (filename string , data string , mode os.FileMode ) error {
1551
- return ioutil .WriteFile (filename , []byte (data ), mode )
1556
+ return os .WriteFile (filename , []byte (data ), mode )
1552
1557
}
1553
1558
1554
1559
// FileGetContents file_get_contents()
1555
1560
func FileGetContents (filename string ) (string , error ) {
1556
- data , err := ioutil .ReadFile (filename )
1561
+ data , err := os .ReadFile (filename )
1557
1562
return string (data ), err
1558
1563
}
1559
1564
@@ -1717,13 +1722,13 @@ func Empty(val interface{}) bool {
1717
1722
// Thus +0123.45e6 is a valid numeric value.
1718
1723
// In PHP hexadecimal (e.g. 0xf4c3b00c) is not supported, but IsNumeric is supported.
1719
1724
func IsNumeric (val interface {}) bool {
1720
- switch val .(type ) {
1725
+ switch val := val .(type ) {
1721
1726
case int , int8 , int16 , int32 , int64 , uint , uint8 , uint16 , uint32 , uint64 :
1722
1727
return true
1723
1728
case float32 , float64 , complex64 , complex128 :
1724
1729
return true
1725
1730
case string :
1726
- str := val .( string )
1731
+ str := val
1727
1732
if str == "" {
1728
1733
return false
1729
1734
}
@@ -1773,8 +1778,9 @@ func IsNumeric(val interface{}) bool {
1773
1778
// returnVar, 0: succ; 1: fail
1774
1779
// Return the last line from the result of the command.
1775
1780
// command format eg:
1776
- // "ls -a"
1777
- // "/bin/bash -c \"ls -a\""
1781
+ //
1782
+ // "ls -a"
1783
+ // "/bin/bash -c \"ls -a\""
1778
1784
func Exec (command string , output * []string , returnVar * int ) string {
1779
1785
q := rune (0 )
1780
1786
parts := strings .FieldsFunc (command , func (r rune ) bool {
@@ -2108,7 +2114,7 @@ func VersionCompare(version1, version2, operator string) bool {
2108
2114
}
2109
2115
} else if ! (p1 [0 ] >= '0' && p1 [0 ] <= '9' ) && ! (p2 [0 ] >= '0' && p2 [0 ] <= '9' ) { // all digit
2110
2116
compare = special (p1 , p2 )
2111
- } else { // part is digit
2117
+ } else { // part is digit
2112
2118
if p1 [0 ] >= '0' && p1 [0 ] <= '9' { // is digit
2113
2119
compare = special ("#N#" , p2 )
2114
2120
} else {
0 commit comments