Remove a number of redundant fns in Engine.Util.Ascii.
* src/engine/util/util-ascii.vala (Geary.Ascii): Remove functions that are now supported by Vala 0.26, that are simple statements, or are only used once elsewhere. Update call sites.
This commit is contained in:
parent
f4f775c8c2
commit
1d8c4aea80
13 changed files with 92 additions and 129 deletions
|
|
@ -25,7 +25,7 @@ private bool is_special_char(char ch, char[] ar, string? exceptions) {
|
|||
return true;
|
||||
|
||||
if (ch in ar)
|
||||
return (exceptions != null) ? Ascii.index_of(exceptions, ch) < 0 : true;
|
||||
return (exceptions != null) ? exceptions.index_of_char(ch) < 0 : true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public class Geary.Imap.FetchBodyDataSpecifier : BaseObject, Gee.Hashable<FetchB
|
|||
if (String.is_empty(value))
|
||||
return NONE;
|
||||
|
||||
switch (Ascii.strdown(value)) {
|
||||
switch (value.down()) {
|
||||
case "header":
|
||||
return HEADER;
|
||||
|
||||
|
|
@ -180,9 +180,11 @@ public class Geary.Imap.FetchBodyDataSpecifier : BaseObject, Gee.Hashable<FetchB
|
|||
this.is_peek = is_peek;
|
||||
|
||||
if (field_names != null && field_names.length > 0) {
|
||||
this.field_names = new Gee.TreeSet<string>(Ascii.strcmp);
|
||||
this.field_names = new Gee.TreeSet<string>((s1, s2) => {
|
||||
return GLib.strcmp(s1, s2);
|
||||
});
|
||||
foreach (string field_name in field_names) {
|
||||
string converted = Ascii.strdown(field_name.strip());
|
||||
string converted = field_name.strip().down();
|
||||
|
||||
if (!String.is_empty(converted))
|
||||
this.field_names.add(converted);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class Geary.Imap.InternalDate : Geary.MessageData.AbstractMessageData, Ge
|
|||
|
||||
// check month (this catches localization problems)
|
||||
int month = -1;
|
||||
string mon_down = Ascii.strdown(((string) mon));
|
||||
string mon_down = ((string) mon).down();
|
||||
for (int ctr = 0; ctr < EN_US_MON_DOWN.length; ctr++) {
|
||||
if (mon_down == EN_US_MON_DOWN[ctr]) {
|
||||
month = ctr;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class Geary.Imap.MailboxSpecifier : BaseObject, Gee.Hashable<MailboxSpeci
|
|||
* @see is_inbox_name
|
||||
*/
|
||||
public static bool is_canonical_inbox_name(string name) {
|
||||
return Ascii.str_equal(name, CANONICAL_INBOX_NAME);
|
||||
return (name == CANONICAL_INBOX_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,7 +183,7 @@ public class Geary.Imap.MailboxSpecifier : BaseObject, Gee.Hashable<MailboxSpeci
|
|||
if (is_inbox)
|
||||
return Ascii.stri_equal(name, other.name);
|
||||
|
||||
return Ascii.str_equal(name, other.name);
|
||||
return (name == other.name);
|
||||
}
|
||||
|
||||
public int compare_to(MailboxSpecifier other) {
|
||||
|
|
@ -193,7 +193,7 @@ public class Geary.Imap.MailboxSpecifier : BaseObject, Gee.Hashable<MailboxSpeci
|
|||
if (is_inbox && other.is_inbox)
|
||||
return 0;
|
||||
|
||||
return Ascii.strcmp(name, other.name);
|
||||
return GLib.strcmp(name, other.name);
|
||||
}
|
||||
|
||||
public string to_string() {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public abstract class Geary.Imap.StringParameter : Geary.Imap.Parameter {
|
|||
* Case-sensitive comparison.
|
||||
*/
|
||||
public bool equals_cs(string value) {
|
||||
return Ascii.str_equal(ascii, value);
|
||||
return (ascii == value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,14 +153,14 @@ public abstract class Geary.Imap.StringParameter : Geary.Imap.Parameter {
|
|||
* Returns the string lowercased.
|
||||
*/
|
||||
public string as_lower() {
|
||||
return Ascii.strdown(ascii);
|
||||
return ascii.down();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string uppercased.
|
||||
*/
|
||||
public string as_upper() {
|
||||
return Ascii.strup(ascii);
|
||||
return ascii.up();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class Geary.Imap.ResponseCodeType : BaseObject, Gee.Hashable<ResponseCode
|
|||
|
||||
// store lowercased so it's easily compared with const strings above
|
||||
original = ascii;
|
||||
value = Ascii.strdown(ascii);
|
||||
value = ascii.down();
|
||||
}
|
||||
|
||||
public bool is_value(string str) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class Geary.Mime.ContentParameters : BaseObject {
|
|||
public bool has_value_cs(string attribute, string value) {
|
||||
string? stored = params.get(attribute);
|
||||
|
||||
return (stored != null) ? Ascii.str_equal(stored, value) : false;
|
||||
return (stored != null) ? (stored == value) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public enum Geary.Mime.DispositionType {
|
|||
if (String.is_empty_or_whitespace(str))
|
||||
return UNSPECIFIED;
|
||||
|
||||
switch (Ascii.strdown(str)) {
|
||||
switch (str.down()) {
|
||||
case "inline":
|
||||
return INLINE;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public enum Geary.Mime.MultipartSubtype {
|
|||
}
|
||||
|
||||
is_unknown = false;
|
||||
switch (Ascii.strdown(content_type.media_subtype)) {
|
||||
switch (content_type.media_subtype.down()) {
|
||||
case "mixed":
|
||||
return MIXED;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class Geary.RFC822.MailboxAddress : Geary.MessageData.SearchableMessageDa
|
|||
|
||||
source_route = null;
|
||||
|
||||
int atsign = Ascii.index_of(address, '@');
|
||||
int atsign = address.index_of_char('@');
|
||||
if (atsign > 0) {
|
||||
mailbox = address.slice(0, atsign);
|
||||
domain = address.slice(atsign + 1, address.length);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public enum Geary.Smtp.Command {
|
|||
}
|
||||
|
||||
public static Command deserialize(string str) throws SmtpError {
|
||||
switch (Ascii.strdown(str)) {
|
||||
switch (str.down()) {
|
||||
case "helo":
|
||||
return HELO;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class Geary.Smtp.Greeting : Response {
|
|||
}
|
||||
|
||||
public static ServerFlavor deserialize(string str) {
|
||||
switch (Ascii.strup(str)) {
|
||||
switch (str.up()) {
|
||||
case "SMTP":
|
||||
return SMTP;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,63 +4,32 @@
|
|||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
*/
|
||||
|
||||
// These calls are bound to the string class in Vala 0.26. When that version of Vala is the
|
||||
// minimum, these can be dropped and Ascii.strup and Ascii.strdown can use the string methods.
|
||||
extern string g_ascii_strup(string str, ssize_t len = -1);
|
||||
extern string g_ascii_strdown(string str, ssize_t len = -1);
|
||||
|
||||
namespace Geary.Ascii {
|
||||
|
||||
public int index_of(string str, char ch) {
|
||||
char *strptr = str;
|
||||
int index = 0;
|
||||
for (;;) {
|
||||
char strch = *strptr++;
|
||||
|
||||
if (strch == String.EOS)
|
||||
return -1;
|
||||
|
||||
if (strch == ch)
|
||||
return index;
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
public bool get_next_char(string str, ref int index, out char ch) {
|
||||
ch = str[index++];
|
||||
|
||||
return ch != String.EOS;
|
||||
}
|
||||
|
||||
public inline int strcmp(string a, string b) {
|
||||
return GLib.strcmp(a, b);
|
||||
}
|
||||
|
||||
public int stricmp(string a, string b) {
|
||||
public bool stri_equal(string a, string b) {
|
||||
// XXX Is this marginally faster than a.down() == b.down() in the
|
||||
// best case, slower in the worse case, so not worth it?
|
||||
char *aptr = a;
|
||||
char *bptr = b;
|
||||
for (;;) {
|
||||
int diff = (int) (*aptr).tolower() - (int) (*bptr).tolower();
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
return false;
|
||||
|
||||
if (*aptr == String.EOS)
|
||||
return 0;
|
||||
return true;
|
||||
|
||||
aptr++;
|
||||
bptr++;
|
||||
}
|
||||
}
|
||||
|
||||
public inline bool str_equal(string a, string b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
public inline bool stri_equal(string a, string b) {
|
||||
return stricmp(a, b) == 0;
|
||||
}
|
||||
|
||||
public bool nullable_stri_equal(string? a, string? b) {
|
||||
if (a == null)
|
||||
return (b == null);
|
||||
|
|
@ -86,14 +55,6 @@ public uint nullable_stri_hash(string? str) {
|
|||
return (str != null) ? stri_hash(str) : 0;
|
||||
}
|
||||
|
||||
public string strdown(string str) {
|
||||
return g_ascii_strdown(str);
|
||||
}
|
||||
|
||||
public string strup(string str) {
|
||||
return g_ascii_strup(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the ASCII string contains only whitespace and at least one numeric character.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue