summaryrefslogtreecommitdiff
path: root/vapi
diff options
context:
space:
mode:
authorwszqkzqk <wszqkzqk@qq.com>2023-01-18 14:25:50 +0800
committerRico Tzschichholz <ricotz@ubuntu.com>2023-01-30 10:31:12 +0100
commit79b6b149219d54fa8b7bf2c3ad367aac4d487cd8 (patch)
treef461a4ba518609cdb9ca79210ae5abf2488d33bb /vapi
parenteb38c29d8f163792be026f46e46c0f86f719d14e (diff)
downloadvala-79b6b149219d54fa8b7bf2c3ad367aac4d487cd8.tar.gz
glib-2.0: Improve string.replace()
Use string.split() and string.joinv() which is way faster than GLib.Regex() Fixes https://gitlab.gnome.org/GNOME/vala/issues/1402
Diffstat (limited to 'vapi')
-rw-r--r--vapi/glib-2.0.vapi12
1 files changed, 4 insertions, 8 deletions
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 497d6bb6c..4e7239fc6 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -1539,16 +1539,12 @@ public class string {
return strstr ((char*) this, (char*) needle) != null;
}
- public string replace (string old, string replacement) {
- if (*((char*) this) == '\0' || *((char*) old) == '\0' || old == replacement)
+ public string replace (string old, string replacement, int max_tokens = -1) {
+ if (*((char*) this) == '\0' || *((char*) old) == '\0'
+ || max_tokens == 0 || old == replacement) {
return this;
-
- try {
- var regex = new GLib.Regex (GLib.Regex.escape_string (old));
- return regex.replace_literal (this, -1, 0, replacement);
- } catch (GLib.RegexError e) {
- GLib.assert_not_reached ();
}
+ return string.joinv (replacement, (string?[]?) this.split (old, max_tokens + 1));
}
[CCode (cname = "g_utf8_strlen")]