github.com/gogf/gf@v1.16.9/text/gstr/gstr_convert.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gstr
     8  
     9  import (
    10  	"regexp"
    11  	"strconv"
    12  )
    13  
    14  var (
    15  	// octReg is the regular expression object for checks octal string.
    16  	octReg = regexp.MustCompile(`\\[0-7]{3}`)
    17  )
    18  
    19  // OctStr converts string container octal string to its original string,
    20  // for example, to Chinese string.
    21  // Eg: `\346\200\241` -> 怡
    22  func OctStr(str string) string {
    23  	return octReg.ReplaceAllStringFunc(
    24  		str,
    25  		func(s string) string {
    26  			i, _ := strconv.ParseInt(s[1:], 8, 0)
    27  			return string([]byte{byte(i)})
    28  		},
    29  	)
    30  }