Skip to content

Commit 558cf5e

Browse files
authored
Merge pull request #43 from l3dlp/master
Fixes Golang 1.19 Warnings
2 parents fc787a7 + e761584 commit 558cf5e

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

php.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"hash/crc32"
1818
"html"
1919
"io"
20-
"io/ioutil"
2120
"math"
2221
"math/big"
2322
"math/rand"
@@ -34,6 +33,9 @@ import (
3433
"time"
3534
"unicode"
3635
"unicode/utf8"
36+
37+
"golang.org/x/text/cases"
38+
"golang.org/x/text/language"
3739
)
3840

3941
//////////// Date/Time Functions ////////////
@@ -206,12 +208,15 @@ func Lcfirst(str string) string {
206208

207209
// Ucwords ucwords()
208210
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
210215
}
211216

212217
// Substr substr()
213218
func Substr(str string, start uint, length int) string {
214-
if start < 0 || length < -1 {
219+
if length < -1 {
215220
return str
216221
}
217222
switch {
@@ -774,7 +779,7 @@ func Md5File(path string) (string, error) {
774779
hash := md5.New()
775780

776781
if fi.Size() < size {
777-
data, err := ioutil.ReadFile(path)
782+
data, err := os.ReadFile(path)
778783
if err != nil {
779784
return "", err
780785
}
@@ -803,7 +808,7 @@ func Sha1(str string) string {
803808

804809
// Sha1File sha1_file()
805810
func Sha1File(path string) (string, error) {
806-
data, err := ioutil.ReadFile(path)
811+
data, err := os.ReadFile(path)
807812
if err != nil {
808813
return "", err
809814
}
@@ -1486,7 +1491,7 @@ func Pathinfo(path string, options int) map[string]string {
14861491
if ((options & 4) == 4) || ((options & 8) == 8) {
14871492
basename := ""
14881493
if (options & 2) == 2 {
1489-
basename, _ = info["basename"]
1494+
basename = info["basename"]
14901495
} else {
14911496
basename = filepath.Base(path)
14921497
}
@@ -1520,11 +1525,11 @@ func FileExists(filename string) bool {
15201525

15211526
// IsFile is_file()
15221527
func IsFile(filename string) bool {
1523-
_, err := os.Stat(filename)
1528+
fd, err := os.Stat(filename)
15241529
if err != nil && os.IsNotExist(err) {
15251530
return false
15261531
}
1527-
return true
1532+
return !fd.IsDir()
15281533
}
15291534

15301535
// IsDir is_dir()
@@ -1548,12 +1553,12 @@ func FileSize(filename string) (int64, error) {
15481553

15491554
// FilePutContents file_put_contents()
15501555
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)
15521557
}
15531558

15541559
// FileGetContents file_get_contents()
15551560
func FileGetContents(filename string) (string, error) {
1556-
data, err := ioutil.ReadFile(filename)
1561+
data, err := os.ReadFile(filename)
15571562
return string(data), err
15581563
}
15591564

@@ -1717,13 +1722,13 @@ func Empty(val interface{}) bool {
17171722
// Thus +0123.45e6 is a valid numeric value.
17181723
// In PHP hexadecimal (e.g. 0xf4c3b00c) is not supported, but IsNumeric is supported.
17191724
func IsNumeric(val interface{}) bool {
1720-
switch val.(type) {
1725+
switch val := val.(type) {
17211726
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
17221727
return true
17231728
case float32, float64, complex64, complex128:
17241729
return true
17251730
case string:
1726-
str := val.(string)
1731+
str := val
17271732
if str == "" {
17281733
return false
17291734
}
@@ -1773,8 +1778,9 @@ func IsNumeric(val interface{}) bool {
17731778
// returnVar, 0: succ; 1: fail
17741779
// Return the last line from the result of the command.
17751780
// command format eg:
1776-
// "ls -a"
1777-
// "/bin/bash -c \"ls -a\""
1781+
//
1782+
// "ls -a"
1783+
// "/bin/bash -c \"ls -a\""
17781784
func Exec(command string, output *[]string, returnVar *int) string {
17791785
q := rune(0)
17801786
parts := strings.FieldsFunc(command, func(r rune) bool {
@@ -2108,7 +2114,7 @@ func VersionCompare(version1, version2, operator string) bool {
21082114
}
21092115
} else if !(p1[0] >= '0' && p1[0] <= '9') && !(p2[0] >= '0' && p2[0] <= '9') { // all digit
21102116
compare = special(p1, p2)
2111-
} else { // part is digit
2117+
} else { // part is digit
21122118
if p1[0] >= '0' && p1[0] <= '9' { // is digit
21132119
compare = special("#N#", p2)
21142120
} else {

0 commit comments

Comments
 (0)