Golang bufio.UnreadRune() function example
package bufio
UnreadRune unreads the last rune. If the most recent read operation on the buffer was not a ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)
Golang bufio.UnreadRune() function usage example
utf8buf := []byte("世界")
readbuffer := bytes.NewBuffer(utf8buf)
reader := bufio.NewReader(readbuffer)
fmt.Println(reader.UnreadRune()) // this will cause error, because there is nothing to "unread"
rune, _, _ := reader.ReadRune() // read first rune which is 世
fmt.Println(string(rune)) // prints 世
rune, _, _ = reader.ReadRune() // read the next rune, which is 界
fmt.Println(string(rune)) // prints 界
fmt.Println(reader.UnreadRune()) // this will NOT cause error, because reader managed to "unread"
Output :
bufio: invalid use of UnreadRune
世
界
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+4.8k Which content-type(MIME type) to use for JSON data
+14.8k Golang : Get URI segments by number and assign as variable example
+18.2k Golang : Get path name to current directory or folder
+16k Golang : Read large file with bufio.Scanner cause token too long error
+10.3k Golang : How to check if a website is served via HTTPS
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+62.7k Golang : Convert HTTP Response body to string
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+9.9k Golang : Translate language with language package example
+6k Golang : How to verify input is rune?
+11.4k Golang : Concatenate (combine) buffer data example