add print-code-points.go
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Sun, 29 Sep 2013 21:52:43 +0000 (14:52 -0700)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Sun, 29 Sep 2013 21:52:56 +0000 (14:52 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

.gitignore
print-code-points.go [new file with mode: 0644]

index 65c02f9..6c30d1d 100644 (file)
@@ -10,6 +10,7 @@ errno_speak
 simple_time
 vimstart
 show_default_sockopts
+print-code-points
 
 #
 # Normal rules
diff --git a/print-code-points.go b/print-code-points.go
new file mode 100644 (file)
index 0000000..1745402
--- /dev/null
@@ -0,0 +1,24 @@
+package main
+
+import (
+       "fmt"
+       "os"
+)
+
+func usage(retval int) {
+       fmt.Printf("print-code-points: prints out the code points in a unicode string.\n" +
+               "\n" +
+               "usage: print-code-points <string>\n")
+       os.Exit(retval)
+}
+
+func main() {
+       if (len(os.Args) != 2) {
+               usage(1)
+       }
+       str := os.Args[1]
+       for pos, codePoint := range str {
+               fmt.Printf("Code Point 0x%04x: '%s'\n", codePoint, str[pos:pos+1])
+       }
+       os.Exit(0)
+}