本文整理汇总了Golang中utf8.NewString函数的典型用法代码示例。如果您正苦于以下问题:Golang NewString函数的具体用法?Golang NewString怎么用?Golang NewString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initFlipped
// initialise the mappings from vanilla runes -> flipped
func initFlipped() {
const (
VANILLA = "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA0987654321&_?!\"'.,;"
FLIPPED = "zʎxʍʌnʇsɹbdouɯlʞɾıɥɓɟǝpɔqɐZ⅄XMΛ∩⊥SᴚΌԀONW˥⋊ſIH⅁ℲƎ◖Ɔ𐐒∀068ㄥ9ގㄣƐᄅ⇂⅋‾¿¡„,˙'؛"
)
var (
vanillaIdx int
runeMap map[int]int
)
vanilla := utf8.NewString(VANILLA)
vanillaIdx = 0
runeMap = make(map[int]int)
for _, r := range FLIPPED {
runeMap[vanilla.At(vanillaIdx)] = r
vanillaIdx++
}
// a function to reverse the runes in a string
reverse := func(s string) string {
us := utf8.NewString(s)
out := ""
for i := us.RuneCount() - 1; i >= 0; i-- {
out += fmt.Sprintf("%c", us.At(i))
}
return out
}
fonts["flipped"] = Font{runeMap, reverse}
}
示例2: MakeACGenEdit
func MakeACGenEdit(Gp [][]string, c []float64) func(string, string) float64 {
Proot := MakeLinkedGoto(Gp[0])
MakeLinkedFail(Proot)
Troot := MakeLinkedGoto(Gp[1])
MakeLinkedFail(Troot)
G := make([][]*utf8.String, len(Gp))
for i, _ := range G {
G[i] = make([]*utf8.String, len(Gp[i]))
for j, _ := range G[i] {
G[i][j] = utf8.NewString(Gp[i][j])
}
}
return func(pattern string, text string) float64 {
P := utf8.NewString(pattern + " ")
PLen := P.RuneCount() - 1
T := utf8.NewString(text + " ")
TLen := T.RuneCount() - 1
d := makeMatrix(TLen+1, PLen+1)
p := NewBitArray(len(Gp[0]))
Pstate := Proot
Tstate := Troot
for x := 0; x <= PLen; x++ {
Tstate = Troot
for y := 0; y <= TLen; y++ {
if x == 0 && y == 0 {
d[y][x] = 0
} else {
d[y][x] = math.Inf(1)
if x > 0 && y > 0 && Pstate.symbol == Tstate.symbol {
d[y][x] = d[y-1][x-1]
}
if len(Pstate.output) > 0 && len(Tstate.output) > 0 {
p = p.Intersection(Pstate.output, Tstate.output)
p.ForEach(func(i int) {
a := x - G[0][i].RuneCount()
b := y - G[1][i].RuneCount()
d[y][x] = math.Fmin(d[y][x], d[b][a]+c[i])
})
}
}
Tstate = Tstate.Push(T.At(y))
}
Pstate = Pstate.Push(P.At(x))
}
return d[TLen][PLen]
}
}
示例3: initBlackLetter
// initialise the mappings from vanilla runes -> blackletter
func initBlackLetter() {
const (
VANILLA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
BLACKLETTER = "𝔄𝔅ℭ𝔇𝔈𝔉𝔊ℌℑ𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔ℜ𝔖𝔗𝔘𝔙𝔚𝔛𝔜ℨ𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷"
BLACKLETTER_BOLD = "𝕬𝕭𝕮𝕯𝕰𝕱𝕲𝕳𝕴𝕵𝕶𝕷𝕸𝕹𝕺𝕻𝕼𝕽𝕾𝕿𝖀𝖁𝖂𝖃𝖄𝖅𝖆𝖇𝖈𝖉𝖊𝖋𝖌𝖍𝖎𝖏𝖐𝖑𝖒𝖓𝖔𝖕𝖖𝖗𝖘𝖙𝖚𝖛𝖜𝖝𝖞𝖟"
)
var (
vanillaIdx int
runeMap map[int]int
)
vanilla := utf8.NewString(VANILLA)
vanillaIdx = 0
runeMap = make(map[int]int)
for _, r := range BLACKLETTER {
runeMap[vanilla.At(vanillaIdx)] = r
vanillaIdx++
}
fonts["blackletter"] = Font{runeMap, nil}
vanillaIdx = 0
runeMap = make(map[int]int)
for _, r := range BLACKLETTER_BOLD {
runeMap[vanilla.At(vanillaIdx)] = r
vanillaIdx++
}
fonts["blackletterbold"] = Font{runeMap, nil}
}
示例4: Literal
func Literal(s string, result interface{}) Parser {
match := utf8.NewString(s)
if len(s) == 0 {
return Return(result)
}
return Sequence_(literalRune(match.At(0)), Literal(match.Slice(1, match.RuneCount()), result))
}
示例5: frame
func frame(data string, json bool) string {
utf8str := utf8.NewString(data)
if json {
return fmt.Sprintf("~m~%d~m~~j~%s", 3+utf8str.RuneCount(), data)
}
return fmt.Sprintf("~m~%d~m~%s", utf8str.RuneCount(), data)
}
示例6: CollectUnexportedObjs
func (this *SingleMover) CollectUnexportedObjs() {
this.unexportedObjs = make(map[*ast.Object]bool)
for node, obj := range this.moveNodes {
//printer.Fprint(os.Stdout, token.NewFileSet(), node)
//fmt.Printf("\n%v %T\n", obj, node)
if !unicode.IsUpper(utf8.NewString(obj.Name).At(0)) {
this.unexportedObjs[obj] = true
}
if ts, ok := node.(*ast.TypeSpec); ok {
if st, ok := ts.Type.(*ast.StructType); ok {
for _, field := range st.Fields.List {
for _, name := range field.Names {
if !name.IsExported() {
obj, _ := types.ExprType(name, LocalImporter)
this.unexportedObjs[obj] = true
}
}
}
}
}
}
return
}
示例7: RandomString
func RandomString(alpha string, min int, max int) string {
alphabet := utf8.NewString(alpha)
runes := make([]int, rand.Intn(max-(min-1))+min)
for i, _ := range runes {
p := rand.Intn(alphabet.RuneCount())
runes[i] = alphabet.At(p)
}
return string(runes)
}
示例8: Substrings
func Substrings(str string) []string {
s := utf8.NewString(str)
n := s.RuneCount()
substrings := make([]string, 0, (n*(n+1))/2)
for start := 0; start < n; start++ {
for end := start + 1; end <= n; end++ {
substrings = append(substrings, s.Slice(start, end))
}
}
return substrings
}
示例9: ParseSumma
func ParseSumma(s string) int64 {
S := utf8.NewString(s)
var i int
for i = 0; i < S.RuneCount(); i++ {
if unicode.IsSpace(S.At(i)) { // конец даты
//DecodeDate(S.Slice(0,i), &lf.curT.date)
break
}
}
return (0)
}
示例10: AddText
func (doc *Document) AddText(text string, font *drawing.Font, color drawing.Color, preferredSize drawing.Size, format drawing.DrawTextFormat) os.Error {
item := &simpleTextItem{
text: utf8.NewString(text),
font: font,
color: color,
preferredSize: preferredSize,
format: format,
parts: make([]*simpleTextPart, 0, 1),
}
return doc.paginateItem(item)
}
示例11: IsLegalIdentifier
func IsLegalIdentifier(s string) bool {
us := utf8.NewString(s)
if !unicode.IsLetter(us.At(0)) {
return false
}
for i, c := range s {
if !unicode.IsLetter(c) && (i == 0 || !unicode.IsDigit(c)) {
return false
}
}
return true
}
示例12: MakeBasicGenEdit
func MakeBasicGenEdit(G [][]string, c []float64) func(string, string) float64 {
cost := func(A string, B string, pi int, d [][]float64) float64 {
a := len(A) - len(G[pi][0])
b := len(B) - len(G[pi][1])
if a >= 0 && b >= 0 && A[a:] == G[pi][0] && B[b:] == G[pi][1] {
return d[b][a] + c[pi]
}
return math.Inf(1)
}
return func(Ap string, Bp string) float64 {
A := utf8.NewString(Ap)
B := utf8.NewString(Bp)
d := makeMatrix(B.RuneCount()+1, A.RuneCount()+1)
for x := 0; x <= A.RuneCount(); x++ {
for y := 0; y <= B.RuneCount(); y++ {
if x == 0 && y == 0 {
d[y][x] = 0
} else {
min := math.Inf(1)
if x > 0 && y > 0 && A.At(x-1) == B.At(y-1) {
min = d[y-1][x-1]
}
for pi, _ := range G {
min = math.Fmin(min,
cost(A.Slice(0, x),
B.Slice(0, y),
pi,
d))
}
d[y][x] = min
}
}
}
return d[B.RuneCount()][A.RuneCount()]
}
}
示例13: translate
func translate(sourcelang, targetlang, text string) string {
uri := fmt.Sprintf("http://translate.google.com/translate_a/t?client=t&hl=%s&sl=%s&tl=en-US&text=%s",
targetlang, sourcelang, url.QueryEscape(text))
b, err := getUserAgent(uri)
if err != nil {
return "Error while requesting translation"
}
result := strings.SplitN(string(b), `"`, 11)
if len(result) < 11 {
return "Error while parsing translation"
}
if sourcelang == "auto" {
return result[9]
}
source := utf8.NewString(result[1])
romanized := utf8.NewString(result[5])
if romanized.RuneCount() > 0 {
if sourcelang == "en" && !strings.Contains(text, " ") {
// Google duplicates when there is only one source word
source_left := source.Slice(0, source.RuneCount()/2)
source_right := source.Slice(source.RuneCount()/2, source.RuneCount())
romanized_left := romanized.Slice(0, romanized.RuneCount()/2)
romanized_right := romanized.Slice(romanized.RuneCount()/2, romanized.RuneCount())
if source_left == source_right &&
strings.ToLower(romanized_left) == strings.ToLower(romanized_right) {
return fmt.Sprintf("%s: %s", source_left, romanized_left)
}
}
return fmt.Sprintf("%s: %s", source, romanized)
}
return source.String()
}
示例14: frame
func frame(data string, typ int, json bool) string {
utf8str := utf8.NewString(data)
switch typ {
case 0:
return "0:0:,"
case 2, 3:
return fmt.Sprintf("%d:%d:%s,", typ, utf8str.RuneCount(), data)
}
if json {
return fmt.Sprintf("%d:%d:j\n:%s,", typ, 3+utf8str.RuneCount(), data)
}
return fmt.Sprintf("%d:%d::%s,", typ, 1+utf8str.RuneCount(), data)
}
示例15: GetMethods
// Returns all available methods
func (this *JsonRPC) GetMethods() (m []Method) {
m = make([]Method, this.object.NumMethod())
j := 0
for i := 0; i < this.object.NumMethod(); i++ {
method := this.object.Type().Method(i)
// Is this a public method?
if unicode.IsUpper(utf8.NewString(method.Name).At(0)) {
m[j].Name = method.Name
// first parameter is the receiver object
// which is provided by us, not the remote caller
m[j].NumParams = this.object.Method(i).Type().NumIn() - 1
j++
}
}
return m[0:j]
}