var define = new StringBuilder ("__");
var i = filename;
- while (i.len () > 0) {
+ while (i.length > 0) {
var c = i.get_char ();
if (c.isalnum () && c < 0x80) {
define.append_unichar (c.toupper ());
var define = new StringBuilder ("__");
var i = filename;
- while (i.len () > 0) {
+ while (i.length > 0) {
var c = i.get_char ();
if (c.isalnum () && c < 0x80) {
define.append_unichar (c.toupper ());
bool is_gtypeinstance = !cl.is_compact;
bool is_fundamental = is_gtypeinstance && cl.base_class == null;
- if (cl.get_cname().len () < 3) {
+ if (cl.get_cname().length < 3) {
cl.error = true;
Report.error (cl.source_reference, "Class name `%s' is too short".printf (cl.get_cname ()));
return;
public override void visit_interface (Interface iface) {
push_context (new EmitContext (iface));
- if (iface.get_cname().len () < 3) {
+ if (iface.get_cname().length < 3) {
iface.error = true;
Report.error (iface.source_reference, "Interface name `%s' is too short".printf (iface.get_cname ()));
return;
if (library != null) {
if (gir != null) {
if (context.profile == Profile.GOBJECT) {
- long gir_len = gir.len ();
+ long gir_len = gir.length;
unowned string? last_hyphen = gir.rchr (gir_len, '-');
if (last_hyphen == null || !gir.has_suffix (".gir")) {
}
private static bool ends_with_dir_separator (string s) {
- return Path.is_dir_separator (s.offset (s.len () - 1).get_char ());
+ return Path.is_dir_separator (s.offset (s.length - 1).get_char ());
}
/* ported from glibc */
// do nothing
} else if (len == 2 && start.has_prefix ("..")) {
// back up to previous component, ignore if at root already
- if (rpath.len () > root_len) {
+ if (rpath.length > root_len) {
do {
- rpath = rpath.substring (0, rpath.len () - 1);
+ rpath = rpath.substring (0, rpath.length - 1);
} while (!ends_with_dir_separator (rpath));
}
} else {
}
}
- if (rpath.len () > root_len && ends_with_dir_separator (rpath)) {
- rpath = rpath.substring (0, rpath.len () - 1);
+ if (rpath.length > root_len && ends_with_dir_separator (rpath)) {
+ rpath = rpath.substring (0, rpath.length - 1);
}
if (Path.DIR_SEPARATOR != '/') {
set {
_value = value;
- if (!value.validate () || (value.len () != 3 && value.next_char ().get_char () != '\\')) {
+ if (!value.validate () || (value.length != 3 && value.next_char ().get_char () != '\\')) {
error = true;
}
}
// remove underscores in some cases to avoid conflicts of type macros
if (lower_case_csuffix.has_prefix ("type_")) {
- lower_case_csuffix = "type" + lower_case_csuffix.offset ("type_".len ());
+ lower_case_csuffix = "type" + lower_case_csuffix.offset ("type_".length);
} else if (lower_case_csuffix.has_prefix ("is_")) {
- lower_case_csuffix = "is" + lower_case_csuffix.offset ("is_".len ());
+ lower_case_csuffix = "is" + lower_case_csuffix.offset ("is_".length);
}
if (lower_case_csuffix.has_suffix ("_class")) {
- lower_case_csuffix = lower_case_csuffix.substring (0, lower_case_csuffix.len () - "_class".len ()) + "class";
+ lower_case_csuffix = lower_case_csuffix.substring (0, lower_case_csuffix.length - "_class".length) + "class";
}
}
return lower_case_csuffix;
string i = name;
- while (i.len () > 0) {
+ while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
str.append_c ('-');
case TokenType.VERBATIM_STRING_LITERAL:
next ();
string raw_string = get_last_string ();
- string escaped_string = raw_string.substring (3, raw_string.len () - 6).escape ("");
+ string escaped_string = raw_string.substring (3, raw_string.length - 6).escape ("");
return new StringLiteral ("\"%s\"".printf (escaped_string), get_src (begin));
case TokenType.NULL:
next ();
bool matches (char* begin, string keyword) {
char* keyword_array = (char *) keyword;
- long len = keyword.len ();
+ long len = keyword.length;
for (int i = 0; i < len; i++) {
if (begin[i] != keyword_array[i]) {
return false;
private void calculate_common_prefix (ref string common_prefix, string cname) {
if (common_prefix == null) {
common_prefix = cname;
- while (common_prefix.len () > 0 && !common_prefix.has_suffix ("_")) {
+ while (common_prefix.length > 0 && !common_prefix.has_suffix ("_")) {
// FIXME: could easily be made faster
common_prefix = common_prefix.ndup (common_prefix.size () - 1);
}
common_prefix = common_prefix.ndup (common_prefix.size () - 1);
}
}
- while (common_prefix.len () > 0 && (!common_prefix.has_suffix ("_") ||
- (cname.offset (common_prefix.length).get_char ().isdigit ()) && (cname.len () - common_prefix.len ()) <= 1)) {
+ while (common_prefix.length > 0 && (!common_prefix.has_suffix ("_") ||
+ (cname.offset (common_prefix.length).get_char ().isdigit ()) && (cname.length - common_prefix.length) <= 1)) {
// enum values may not consist solely of digits
common_prefix = common_prefix.ndup (common_prefix.size () - 1);
}
if (m.name == "new") {
m.name = null;
} else if (m.name.has_prefix ("new_")) {
- m.name = m.name.offset ("new_".len ());
+ m.name = m.name.offset ("new_".length);
}
if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "parameters") {
start_element ("parameters");
// remove underscores in some cases to avoid conflicts of type macros
if (result.has_prefix ("type_")) {
- result = "type" + result.offset ("type_".len ());
+ result = "type" + result.offset ("type_".length);
} else if (result.has_prefix ("is_")) {
- result = "is" + result.offset ("is_".len ());
+ result = "is" + result.offset ("is_".length);
}
if (result.has_suffix ("_class")) {
- result = result.substring (0, result.len () - "_class".len ()) + "class";
+ result = result.substring (0, result.length - "_class".length) + "class";
}
return result;
case TokenType.VERBATIM_STRING_LITERAL:
next ();
string raw_string = get_last_string ();
- string escaped_string = raw_string.substring (3, raw_string.len () - 6).escape ("");
+ string escaped_string = raw_string.substring (3, raw_string.length - 6).escape ("");
return new StringLiteral ("\"%s\"".printf (escaped_string), get_src (begin));
case TokenType.NULL:
next ();
string i = name;
- while (i.len () > 0) {
+ while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
str.append_c ('-');
static bool matches (char* begin, string keyword) {
char* keyword_array = (char*) keyword;
- long len = keyword.len ();
+ long len = keyword.length;
for (int i = 0; i < len; i++) {
if (begin[i] != keyword_array[i]) {
return false;
string i = get_cname ();
- while (i.len () > 0) {
+ while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
str.append_c ('-');
// filename and basedir are already canonicalized
if (filename.has_prefix (context.basedir + "/")) {
var basename = Path.get_basename (filename);
- var subdir = filename.substring (context.basedir.len (), filename.len () - context.basedir.len () - basename.len ());
+ var subdir = filename.substring (context.basedir.length, filename.length - context.basedir.length - basename.length);
while (subdir[0] == '/') {
subdir = subdir.offset (1);
}
}
/* remove quotes */
- var noquotes = value.substring (1, (uint) (value.len () - 2));
+ var noquotes = value.substring (1, (uint) (value.length - 2));
/* unescape string */
return noquotes.compress ();
}
weak string i = camel_case;
bool first = true;
- while (i.len () > 0) {
+ while (i.length > 0) {
unichar c = i.get_char ();
if (c.isupper () && !first) {
/* current character is upper case and
bool prev_upper = t.get_char ().isupper ();
t = i.next_char ();
bool next_upper = t.get_char ().isupper ();
- if (!prev_upper || (i.len () >= 2 && !next_upper)) {
+ if (!prev_upper || (i.length >= 2 && !next_upper)) {
/* previous character wasn't upper case or
* next character isn't upper case*/
- long len = result_builder.str.len ();
+ long len = result_builder.str.length;
if (len != 1 && result_builder.str.offset (len - 2).get_char () != '_') {
/* we're not creating 1 character words */
result_builder.append_c ('_');
weak string i = lower_case;
bool last_underscore = true;
- while (i.len () > 0) {
+ while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
last_underscore = true;
public long pointer_to_offset (string pos);
[CCode (cname = "g_utf8_prev_char")]
public unowned string prev_char ();
+ [Deprecated (replacement = "string.length")]
[CCode (cname = "g_utf8_strlen")]
public long len (ssize_t max = -1);
[CCode (cname = "g_utf8_strchr")]
public string ndup (size_t n);
public string substring (long offset, long len = -1) {
- long string_length = this.len ();
+ long string_length = this.length;
if (offset < 0) {
offset = string_length + offset;
GLib.return_val_if_fail (offset >= 0, null);
}
public string slice (long start, long end) {
- long string_length = this.len ();
+ long string_length = this.length;
if (start < 0) {
start = string_length + start;
}
}
public string splice (long start, long end, string? str = null) {
- long string_length = this.len ();
+ long string_length = this.length;
if (start < 0) {
start = string_length + start;
}
}
}
+ [CCode (cname = "g_utf8_strlen")]
+ long utf8_strlen (ssize_t max);
+
public long length {
- get { return this.len (); }
+ get { return this.utf8_strlen (-1); }
}
public uint8[] data {
}
if (type_name.has_prefix (ns.name)) {
- return type_name.offset (ns.name.len ());
+ return type_name.offset (ns.name.length);
} else if (ns.name == "GLib" && type_name.has_prefix ("G")) {
return type_name.offset (1);
} else {
string best_match = null;
foreach (string cprefix in ns.get_cprefixes ()) {
if (type_name.has_prefix (cprefix)) {
- if (best_match == null || cprefix.len () > best_match.len ())
+ if (best_match == null || cprefix.length > best_match.length)
best_match = cprefix;
}
}
if (best_match != null) {
- return type_name.offset (best_match.len ());;
+ return type_name.offset (best_match.length);;
}
}
private string fix_const_name (string const_name, Namespace ns) {
if (const_name.has_prefix (ns.name.up () + "_")) {
- return const_name.offset (ns.name.len () + 1);
+ return const_name.offset (ns.name.length + 1);
} else if (ns.name == "GLib" && const_name.has_prefix ("G_")) {
return const_name.offset (2);
}
if (common_prefix == null) {
common_prefix = value.name;
- while (common_prefix.len () > 0 && !common_prefix.has_suffix ("_")) {
+ while (common_prefix.length > 0 && !common_prefix.has_suffix ("_")) {
// FIXME: could easily be made faster
common_prefix = common_prefix.ndup (common_prefix.size () - 1);
}
common_prefix = common_prefix.ndup (common_prefix.size () - 1);
}
}
- while (common_prefix.len () > 0 && (!common_prefix.has_suffix ("_") ||
- (value.name.offset (common_prefix.length).get_char ().isdigit ()) && (value.name.len () - common_prefix.len ()) <= 1)) {
+ while (common_prefix.length > 0 && (!common_prefix.has_suffix ("_") ||
+ (value.name.offset (common_prefix.length).get_char ().isdigit ()) && (value.name.length - common_prefix.length) <= 1)) {
// enum values may not consist solely of digits
common_prefix = common_prefix.ndup (common_prefix.size () - 1);
}
}
if (!is_hidden) {
- var ev = new EnumValue (value2.name.offset (common_prefix.len ()), null);
+ var ev = new EnumValue (value2.name.offset (common_prefix.length), null);
en.add_value (ev);
}
}
}
if (n.has_prefix ("const-")) {
- n = n.offset ("const-".len ());
+ n = n.offset ("const-".length);
}
if (type_node.is_pointer &&
var nv = attr.split ("=", 2);
if (nv[0] == "cprefix") {
- type.unresolved_symbol = new UnresolvedSymbol (null, n.offset (eval (nv[1]).len ()));
+ type.unresolved_symbol = new UnresolvedSymbol (null, n.offset (eval (nv[1]).length));
} else if (nv[0] == "name") {
type.unresolved_symbol = new UnresolvedSymbol (null, eval (nv[1]));
} else if (nv[0] == "namespace") {
}
if (n.has_prefix (current_namespace.name)) {
- type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.name), n.offset (current_namespace.name.len ()));
+ type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.name), n.offset (current_namespace.name.length));
} else if (n.has_prefix ("G")) {
type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, "GLib"), n.offset (1));
} else {
}
if (type_arg.has_prefix ("unowned ")) {
- type_arg = type_arg.offset ("unowned ".len ());
+ type_arg = type_arg.offset ("unowned ".length);
is_unowned = true;
}
if (m.name == "new") {
m.name = null;
} else if (m.name.has_prefix ("new_")) {
- m.name = m.name.offset ("new_".len ());
+ m.name = m.name.offset ("new_".length);
}
// For classes, check whether a creation method return type equals to the
// type of the class created. If the types do not match (e.g. in most
// class method
m.binding = MemberBinding.CLASS;
if (m.name.has_prefix ("class_")) {
- m.name = m.name.substring ("class_".len (), m.name.len () - "class_".len ());
+ m.name = m.name.substring ("class_".length, m.name.length - "class_".length);
}
continue;
} else {
p.initializer = new StringLiteral ("\"\"", param_type.source_reference);
} else {
unowned string endptr;
- unowned string val_end = val.offset (val.len ());
+ unowned string val_end = val.offset (val.length);
val.to_long (out endptr);
if ((long)endptr == (long)val_end) {
string i = name;
- while (i.len () > 0) {
+ while (i.length > 0) {
unichar c = i.get_char ();
if (c == '-') {
str.append_c ('_');
GLib.SList<string> attr_list = new GLib.SList<string> ();
var attr = new GLib.StringBuilder.sized (attributes.size ());
- var attributes_len = attributes.len ();
+ var attributes_len = attributes.length;
unowned string remaining = attributes;
bool quoted = false, escaped = false;
for (int b = 0 ; b < attributes_len ; b++) {
continue;
}
- var depsfile = source.substring (0, source.len () - "gi".len ()) + "deps";
+ var depsfile = source.substring (0, source.length - "gi".length) + "deps";
if (!FileUtils.test (depsfile, FileTest.EXISTS)) continue;