-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path03-strings.pl6
38 lines (28 loc) · 851 Bytes
/
03-strings.pl6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use v6.c;
use lib 'lib';
use Inline::Go;
my $code = '
package main
import ( "C"; "unicode/utf8" )
//export GetCharCount
func GetCharCount( cstr *C.char ) int {
return utf8.RuneCountInString( C.GoString( cstr ) )
}
//export GetByteCount
func GetByteCount( cstr *C.char ) int {
return len( C.GoString( cstr ) )
}
//export AddString
func AddString( cstr1 *C.char, cstr2 *C.char ) *C.char {
return C.CString( C.GoString( cstr1 ) + C.GoString( cstr2 ) )
}
func main() { }
';
my $go = Inline::Go.new( :code( $code ) );
$go.import-all;
my $str = "\c[WINKING FACE]\c[RELIEVED FACE]";
say "Character count of '$str' is = " ~ $go.GetCharCount($str);
say "Byte count of '$str' is = " ~ $go.GetByteCount($str);
my $s1 = 'Hello ';
my $s2 = "World \c[WINKING FACE]";
printf( "'%s' + '%s' = '%s'\n", $s1, $s2, $go.AddString( $s1, $s2 ) );