if (!ccode_only && !compile_only && output == null) {
// strip extension if there is one
// else we use the default output file of the C compiler
- if (sources[0].rchr (-1, '.') != null) {
- long dot = (long) ((char*) sources[0].rchr (-1, '.') - (char*) sources[0]);
+ if (sources[0].last_index_of_char ('.') != -1) {
+ int dot = sources[0].last_index_of_char ('.');
output = Path.get_basename (sources[0].substring (0, dot));
}
}
if (gir != null) {
if (context.profile == Profile.GOBJECT) {
long gir_len = gir.length;
- unowned string? last_hyphen = gir.rchr (gir_len, '-');
+ int last_hyphen = gir.last_index_of_char ('-');
- if (last_hyphen == null || !gir.has_suffix (".gir")) {
+ if (last_hyphen == -1 || !gir.has_suffix (".gir")) {
Report.error (null, "GIR file name `%s' is not well-formed, expected NAME-VERSION.gir".printf (gir));
} else {
- long offset = (long) ((char*) last_hyphen - (char*) gir);
- string gir_namespace = gir.substring (0, offset);
- string gir_version = gir.substring (offset + 1, gir_len - offset - 5);
+ string gir_namespace = gir.substring (0, last_hyphen);
+ string gir_version = gir.substring (last_hyphen + 1, gir_len - last_hyphen - 5);
gir_version.canon ("0123456789.", '?');
if (gir_namespace == "" || gir_version == "" || !gir_version[0].isdigit () || gir_version.contains ("?")) {
Report.error (null, "GIR file name `%s' is not well-formed, expected NAME-VERSION.gir".printf (gir));
static char* strrstr (char* haystack, char* needle);
[CCode (cname = "g_utf8_strchr")]
static char* utf8_strchr (char* str, ssize_t len, unichar c);
+ [CCode (cname = "g_utf8_strrchr")]
+ static char* utf8_strrchr (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 last_index_of_char (unichar c, int start_index = 0) {
+ char* result = utf8_strrchr ((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.index_of_char")]
[CCode (cname = "g_utf8_strchr")]
public unowned string chr (ssize_t len, unichar c);
+ [Deprecated (replacement = "string.last_index_of_char")]
[CCode (cname = "g_utf8_strrchr")]
public unowned string rchr (ssize_t len, unichar c);
[CCode (cname = "g_utf8_strreverse")]