[pypy-svn] pypy default: Implement str.rsplit for the cli backend
amauryfa
commits-noreply at bitbucket.org
Wed Mar 30 19:54:02 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r43027:56cab8762a29
Date: 2011-03-30 13:28 +0200
http://bitbucket.org/pypy/pypy/changeset/56cab8762a29/
Log: Implement str.rsplit for the cli backend
diff --git a/pypy/translator/cli/src/pypylib.cs b/pypy/translator/cli/src/pypylib.cs
--- a/pypy/translator/cli/src/pypylib.cs
+++ b/pypy/translator/cli/src/pypylib.cs
@@ -26,7 +26,10 @@
else {
string res = "";
foreach(char ch in x)
- res+= string.Format("\\x{0:X2}", (int)ch);
+ if (ch >= 32 && ch < 128)
+ res+= ch;
+ else
+ res+= string.Format("\\x{0:X2}", (int)ch);
return string.Format("'{0}'", res);
}
}
@@ -725,6 +728,25 @@
return s.Split(new Char[] {ch}, max + 1);
}
+ public static string[] ll_rsplit_chr(string s, char ch, int max)
+ {
+ string[] splits = s.Split(ch);
+ if (max < 0 || splits.Length <= max + 1)
+ return splits;
+ else {
+ /* XXX not very efficient */
+ string first = splits[0];
+ // join the first (length - max - 1) items
+ int i;
+ for (i = 1; i < splits.Length - max; i++)
+ first += ch + splits[i];
+ splits[0] = first;
+ Array.Copy(splits, i, splits, 1, max);
+ Array.Resize(ref splits, max + 1);
+ return splits;
+ }
+ }
+
public static bool ll_contains(string s, char ch)
{
return s.IndexOf(ch) != -1;
More information about the Pypy-commit
mailing list