Commit 4eaa4354 authored by Jürg Billeter's avatar Jürg Billeter

glib-2.0: Deprecate string.len () in favor of string.length

parent 9d947dff
......@@ -719,7 +719,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
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 ());
......
......@@ -398,7 +398,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
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 ());
......
......@@ -526,7 +526,7 @@ public class Vala.GTypeModule : GErrorModule {
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;
......@@ -1937,7 +1937,7 @@ public class Vala.GTypeModule : GErrorModule {
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;
......
......@@ -460,7 +460,7 @@ class Vala.Compiler {
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")) {
......@@ -541,7 +541,7 @@ class Vala.Compiler {
}
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 */
......@@ -586,9 +586,9 @@ class Vala.Compiler {
// 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 {
......@@ -600,8 +600,8 @@ class Vala.Compiler {
}
}
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 != '/') {
......
......@@ -38,7 +38,7 @@ public class Vala.CharacterLiteral : Literal {
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;
}
}
......
......@@ -595,12 +595,12 @@ public class Vala.Class : ObjectTypeSymbol {
// 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;
......
......@@ -48,7 +48,7 @@ public class Vala.EnumValue : Constant {
string i = name;
while (i.len () > 0) {
while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
str.append_c ('-');
......
......@@ -363,7 +363,7 @@ public class Vala.Genie.Parser : CodeVisitor {
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 ();
......
......@@ -1391,7 +1391,7 @@ public class Vala.Genie.Scanner {
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;
......
......@@ -307,7 +307,7 @@ public class Vala.GirParser : CodeVisitor {
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);
}
......@@ -316,8 +316,8 @@ public class Vala.GirParser : CodeVisitor {
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);
}
......@@ -1018,7 +1018,7 @@ public class Vala.GirParser : CodeVisitor {
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");
......
......@@ -321,12 +321,12 @@ public class Vala.Interface : ObjectTypeSymbol {
// 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;
......
......@@ -308,7 +308,7 @@ public class Vala.Parser : CodeVisitor {
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 ();
......
......@@ -250,7 +250,7 @@ public class Vala.Property : Symbol, Lockable {
string i = name;
while (i.len () > 0) {
while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
str.append_c ('-');
......
......@@ -1193,7 +1193,7 @@ public class Vala.Scanner {
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;
......
......@@ -174,7 +174,7 @@ public class Vala.Signal : Symbol, Lockable {
string i = get_cname ();
while (i.len () > 0) {
while (i.length > 0) {
unichar c = i.get_char ();
if (c == '_') {
str.append_c ('-');
......
......@@ -170,7 +170,7 @@ public class Vala.SourceFile {
// 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);
}
......
......@@ -54,7 +54,7 @@ public class Vala.StringLiteral : Literal {
}
/* 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 ();
}
......
......@@ -282,7 +282,7 @@ public abstract class Vala.Symbol : CodeNode {
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
......@@ -291,10 +291,10 @@ public abstract class Vala.Symbol : CodeNode {
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 ('_');
......@@ -323,7 +323,7 @@ public abstract class Vala.Symbol : CodeNode {
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;
......
......@@ -976,6 +976,7 @@ public class string {
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")]
......@@ -1083,7 +1084,7 @@ public class string {
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);
......@@ -1099,7 +1100,7 @@ public class string {
}
public string slice (long start, long end) {
long string_length = this.len ();
long string_length = this.length;
if (start < 0) {
start = string_length + start;
}
......@@ -1114,7 +1115,7 @@ public class string {
}
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;
}
......@@ -1162,8 +1163,11 @@ public class string {
}
}
[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 {
......
......@@ -162,20 +162,20 @@ public class Vala.GIdlParser : CodeVisitor {
}
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);;
}
}
......@@ -184,7 +184,7 @@ public class Vala.GIdlParser : CodeVisitor {
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);
}
......@@ -1010,7 +1010,7 @@ public class Vala.GIdlParser : CodeVisitor {
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);
}
......@@ -1019,8 +1019,8 @@ public class Vala.GIdlParser : CodeVisitor {
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);
}
......@@ -1084,7 +1084,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
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);
}
}
......@@ -1456,7 +1456,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
if (n.has_prefix ("const-")) {
n = n.offset ("const-".len ());
n = n.offset ("const-".length);
}
if (type_node.is_pointer &&
......@@ -1567,7 +1567,7 @@ public class Vala.GIdlParser : CodeVisitor {
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") {
......@@ -1589,7 +1589,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
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 {
......@@ -1622,7 +1622,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
if (type_arg.has_prefix ("unowned ")) {
type_arg = type_arg.offset ("unowned ".len ());
type_arg = type_arg.offset ("unowned ".length);
is_unowned = true;
}
......@@ -1649,7 +1649,7 @@ public class Vala.GIdlParser : CodeVisitor {
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
......@@ -1806,7 +1806,7 @@ public class Vala.GIdlParser : CodeVisitor {
// 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 {
......@@ -1949,7 +1949,7 @@ public class Vala.GIdlParser : CodeVisitor {
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) {
......@@ -2086,7 +2086,7 @@ public class Vala.GIdlParser : CodeVisitor {
string i = name;
while (i.len () > 0) {
while (i.length > 0) {
unichar c = i.get_char ();
if (c == '-') {
str.append_c ('_');
......@@ -2378,7 +2378,7 @@ public class Vala.GIdlParser : CodeVisitor {
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++) {
......
......@@ -131,7 +131,7 @@ class Vala.VAPIGen : Object {
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;
......
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