Last active
August 2, 2018 08:45
-
-
Save ysugimoto/447e2dbcc0002194f20bba8162965ea4 to your computer and use it in GitHub Desktop.
Detect surrogate pair on Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func detect_nullbyte(str string) bool { | |
for _, b := range str { | |
if b == '\u0000' { | |
return true | |
} | |
} | |
return false | |
} | |
func main() { | |
notExists := "Golang" | |
exists := "Golang\000" | |
fmt.Println(detect_nullbyte(notExists)) // => false | |
fmt.Println(detect_nullbyte(exists)) // => true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func detect_surrogate(str string) bool { | |
return (len([]byte(str)) % len([]rune(str))) > 0 | |
} | |
func main() { | |
notExists := "吉野家で鯵" | |
exists := "𠮷野家で𩸽" | |
fmt.Println(detect_surrogate(notExists)) // => false | |
fmt.Println(detect_surrogate(exists)) // => true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment