Custom Go bindings for some String methods.

Map C int32_t to Go rune when representing Unicode code points.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/4028a4d4
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/4028a4d4
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/4028a4d4

Branch: refs/heads/master
Commit: 4028a4d4fb37a9ca15592f6e6bb2399f3050fc8e
Parents: 0fdbd3d
Author: Marvin Humphrey <[email protected]>
Authored: Sat May 23 16:01:02 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Thu May 28 17:48:20 2015 -0700

----------------------------------------------------------------------
 runtime/go/build.go               |  6 ++++++
 runtime/go/clownfish/clownfish.go | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4028a4d4/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index 4a182c7..186eebd 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -142,6 +142,12 @@ func specMethods(parcel *cfc.Parcel) {
        errBinding := cfc.NewGoClass(parcel, "Clownfish::Err")
        errBinding.SpecMethod("", "Error() string")
        errBinding.Register()
+
+       stringBinding := cfc.NewGoClass(parcel, "Clownfish::String")
+       stringBinding.SpecMethod("Code_Point_At", "CodePointAt(uintptr) rune")
+       stringBinding.SpecMethod("Code_Point_From", "CodePointFrom(uintptr) 
rune")
+       stringBinding.SpecMethod("Swap_Chars", "SwapChars(rune, rune) string")
+       stringBinding.Register()
 }
 
 func prep() {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4028a4d4/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go 
b/runtime/go/clownfish/clownfish.go
index 143c7c6..b68bf9b 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -154,3 +154,22 @@ func TrapErr(routine func()) (trapped error) {
        routine()
        return trapped
 }
+
+func (s *StringIMP) CodePointAt(tick uintptr) rune {
+       self := ((*C.cfish_String)(unsafe.Pointer(s.TOPTR())))
+       retvalCF := C.CFISH_Str_Code_Point_At(self, C.size_t(tick))
+       return rune(retvalCF)
+}
+
+func (s *StringIMP) CodePointFrom(tick uintptr) rune {
+       self := ((*C.cfish_String)(unsafe.Pointer(s.TOPTR())))
+       retvalCF := C.CFISH_Str_Code_Point_From(self, C.size_t(tick))
+       return rune(retvalCF)
+}
+
+func (s *StringIMP) SwapChars(match, replacement rune) string {
+       self := ((*C.cfish_String)(unsafe.Pointer(s.TOPTR())))
+       retvalCF := C.CFISH_Str_Swap_Chars(self, C.int32_t(match), 
C.int32_t(replacement))
+       defer C.cfish_dec_refcount(unsafe.Pointer(retvalCF))
+       return CFStringToGo(unsafe.Pointer(retvalCF))
+}

Reply via email to