github.com/sandwich-go/boost@v1.3.29/xstrings/xstrings.go (about)

     1  package xstrings
     2  
     3  import (
     4  	"strings"
     5  	"unicode"
     6  )
     7  
     8  // FirstUpper 首字符大写
     9  func FirstUpper(s string) string {
    10  	var result string
    11  	for i, word := range s {
    12  		w := word
    13  		if i == 0 {
    14  			w = unicode.ToUpper(w)
    15  		}
    16  		result += string(w)
    17  	}
    18  	return result
    19  }
    20  
    21  // FirstLower 首字符小写
    22  func FirstLower(s string) string {
    23  	var result string
    24  	for i, word := range s {
    25  		w := word
    26  		if i == 0 {
    27  			w = unicode.ToLower(w)
    28  		}
    29  		result += string(w)
    30  	}
    31  	return result
    32  }
    33  
    34  // HasPrefixIgnoreCase 前缀匹配
    35  func HasPrefixIgnoreCase(str, prefix string) bool {
    36  	return strings.HasPrefix(strings.ToLower(str), strings.ToLower(prefix))
    37  }
    38  
    39  // TrimPrefixIgnoreCase 移除前缀,不区分大小写
    40  func TrimPrefixIgnoreCase(str, prefix string) string {
    41  	if !HasPrefixIgnoreCase(str, prefix) {
    42  		return str
    43  	}
    44  	return strings.TrimSpace(str[len(prefix):])
    45  }