[CCode (cname = "strstr")]
static char* strstr (char* haystack, char* needle);
+ [CCode (cname = "g_utf8_strchr")]
+ static char* utf8_strchr (char* str, ssize_t len, unichar c);
public int index_of (string needle, int start_index = 0) {
char* result = strstr ((char*) this + start_index, (char*) needle);
}
}
+ public int index_of_char (unichar c, int start_index = 0) {
+ char* result = utf8_strchr ((char*) this + start_index, -1, c);
+
+ 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")]
[Deprecated (replacement = "string.length")]
[CCode (cname = "strlen")]
public long len ();
+ [Deprecated (replacement = "string.index_of_char")]
[CCode (cname = "g_utf8_strchr")]
public unowned string chr (ssize_t len, unichar c);
[CCode (cname = "g_utf8_strrchr")]
continue;
}
- if (null != tokens[0].chr (-1, '*')) {
+ if (-1 != tokens[0].index_of_char ('*')) {
PatternSpec* pattern = new PatternSpec (tokens[0]);
codenode_attributes_patterns[pattern] = tokens[0];
}
var attributes = codenode_attributes_map.get (codenode);
if (attributes == null) {
- var dot_required = (null != codenode.chr (-1, '.'));
- var colon_required = (null != codenode.chr (-1, ':'));
+ var dot_required = (-1 != codenode.index_of_char ('.'));
+ var colon_required = (-1 != codenode.index_of_char (':'));
var pattern_specs = codenode_attributes_patterns.get_keys ();
foreach (PatternSpec* pattern in pattern_specs) {
var pspec = codenode_attributes_patterns[pattern];
- if ((dot_required && null == pspec.chr (-1, '.')) ||
- (colon_required && null == pspec.chr (-1, ':'))) {
+ if ((dot_required && -1 != pspec.index_of_char ('.')) ||
+ (colon_required && -1 != pspec.index_of_char (':'))) {
continue;
}