Commit 9c9c5a17 authored by Jürg Billeter's avatar Jürg Billeter

glib-2.0: Add string.index_of

This deprecates string.str.
parent bd05eda8
......@@ -136,7 +136,7 @@ public class Vala.DBusModule : GAsyncModule {
}
var type_args = datatype.get_type_arguments ();
if (sig != null && sig.str ("%s") != null && type_args.size > 0) {
if (sig != null && "%s" in sig && type_args.size > 0) {
string element_sig = "";
foreach (DataType type_arg in type_args) {
var s = get_type_signature (type_arg);
......
......@@ -132,7 +132,7 @@ public class Vala.GVariantModule : GAsyncModule {
}
var type_args = datatype.get_type_arguments ();
if (sig != null && sig.str ("%s") != null && type_args.size > 0) {
if (sig != null && "%s" in sig && type_args.size > 0) {
string element_sig = "";
foreach (DataType type_arg in type_args) {
var s = get_type_signature (type_arg);
......
......@@ -217,7 +217,7 @@ public abstract class Vala.Symbol : CodeNode {
string parent_gir_name = parent_symbol.get_full_gir_name ();
string self_gir_name = gir_name.has_prefix (".") ? gir_name.substring (1) : gir_name;
if (parent_gir_name.str (".") != null) {
if ("." in parent_gir_name) {
return "%s%s".printf (parent_gir_name, self_gir_name);
} else {
return "%s.%s".printf (parent_gir_name, self_gir_name);
......
......@@ -955,12 +955,27 @@ public enum NormalizeMode {
[GIR (name = "utf8")]
[CCode (cname = "gchar", const_cname = "const gchar", copy_function = "g_strdup", free_function = "g_free", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", param_spec_function = "g_param_spec_string", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", take_value_function = "g_value_take_string", type_signature = "s")]
public class string {
[Deprecated (replacement = "string.index_of")]
[CCode (cname = "strstr")]
public unowned string? str (string needle);
[CCode (cname = "g_strrstr")]
public unowned string? rstr (string needle);
[CCode (cname = "g_strrstr_len")]
public unowned string? rstr_len (ssize_t haystack_len, string needle);
[CCode (cname = "strstr")]
static char* strstr (char* haystack, char* needle);
public int index_of (string needle, int start_index = 0) {
char* result = strstr ((char*) this + start_index, (char*) needle);
if (result != null) {
return (int) (result - (char*) this);
} else {
return -1;
}
}
[CCode (cname = "g_str_has_prefix")]
public bool has_prefix (string prefix);
[CCode (cname = "g_str_has_suffix")]
......@@ -1209,7 +1224,7 @@ public class string {
}
public bool contains (string needle) {
return this.str (needle) != null;
return strstr ((char*) this, (char*) needle) != null;
}
public string replace (string old, string replacement) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment