Created
May 27, 2009 15:40
-
-
Save masak/118700 to your computer and use it in GitHub Desktop.
This file contains 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
$ git diff | |
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm | |
index 2aa70e9..578d050 100644 | |
--- a/src/setting/Any-str.pm | |
+++ b/src/setting/Any-str.pm | |
@@ -1,4 +1,43 @@ | |
class Any is also { | |
+ our Int multi method bytes() is export { | |
+ Q:PIR { | |
+ .local string str | |
+ .local pmc chars | |
+ .local pmc bytes | |
+ .local int count | |
+ .local string nextchar | |
+ .local int charcode | |
+ .local string hexstring | |
+ .local int hexstringlength | |
+ .local string firsttwo | |
+ str = self | |
+ chars = split '', str | |
+ bytes = new 'FixedIntegerArray' | |
+ set bytes, 1 | |
+ count = 0 | |
+ loop: | |
+ unless bytes goto done | |
+ nextchar = shift chars | |
+ charcode = ord nextchar | |
+ bytes[0] = charcode | |
+ hexstring = sprintf '%08x', bytes | |
+ nibble: | |
+ hexstringlength = length hexstring | |
+ if hexstringlength == 2 goto inc_length | |
+ firsttwo = substr hexstring, 0, 2 | |
+ unless firsttwo == '00' goto inc_length | |
+ hexstring = substr hexstring, 2 | |
+ goto nibble | |
+ inc_length: | |
+ hexstringlength = length hexstring | |
+ count = count + hexstringlength | |
+ goto loop | |
+ done: | |
+ count = count / 2 | |
+ %r = box count | |
+ } | |
+ } | |
+ | |
our Str multi method capitalize() is export { | |
self.lc.subst(/\w+/, { .ucfirst }, :global) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment