Created
August 13, 2021 02:35
-
-
Save ianfoo/6735fad74dfd5187838265161ea4b655 to your computer and use it in GitHub Desktop.
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
// Generate a test input for rmchar.go. | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
w := bufio.NewWriter(os.Stdout) | |
fmt.Fprintln(w, "hello there") | |
for r := '\200'; r <= '\377'; r++ { | |
fmt.Fprint(w, string(r)) | |
} | |
fmt.Fprintln(w, "okay, all done") | |
w.Flush() | |
} |
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
// Remove chars \200 through \377 from input. | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { | |
var ( | |
in = bufio.NewReader(os.Stdin) | |
out = bufio.NewWriter(os.Stdout) | |
err error | |
) | |
for { | |
var r rune | |
r, _, err = in.ReadRune() | |
if err != nil { | |
break | |
} | |
if r >= '\200' && r <= '\377' { | |
continue | |
} | |
_, err = out.WriteRune(r) | |
if err != nil { | |
break | |
} | |
} | |
if err != io.EOF { | |
fmt.Fprintf(os.Stderr, "error: %v\n", err) | |
} | |
out.Flush() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment