[hyena] Sync Hyena with Banshee's version
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hyena] Sync Hyena with Banshee's version
- Date: Tue, 12 Jan 2010 20:23:58 +0000 (UTC)
commit f3da85f5485b79b42a07b43ebc2209dd504bdd6d
Author: Gabriel Burt <gabriel burt gmail com>
Date: Tue Jan 12 12:03:35 2010 -0800
Sync Hyena with Banshee's version
src/Hyena/Hyena.Collections/Selection.cs | 26 ++++++++++++++++--
src/Hyena/Hyena.Json/Tests/TokenizerTests.cs | 32 +++++++++++-----------
src/Hyena/Hyena.Json/Token.cs | 5 +++
src/Hyena/Hyena.Json/TokenType.cs | 7 +++--
src/Hyena/Hyena.Json/Tokenizer.cs | 36 +++++++++++++++++--------
src/Hyena/Hyena.Query/AliasedObjectSet.cs | 12 +++++---
src/Hyena/Hyena.Query/QueryTermNode.cs | 3 +-
src/Hyena/Hyena.Query/Tests/QueryTests.cs | 2 +
src/Hyena/Hyena/StringUtil.cs | 19 +++++++++----
src/Hyena/Hyena/Tests/StringUtilTests.cs | 24 +++++++----------
src/Hyena/Hyena/ThreadAssist.cs | 20 +++++++++++++-
11 files changed, 125 insertions(+), 61 deletions(-)
---
diff --git a/src/Hyena/Hyena.Collections/Selection.cs b/src/Hyena/Hyena.Collections/Selection.cs
index d0e671d..39a86b1 100644
--- a/src/Hyena/Hyena.Collections/Selection.cs
+++ b/src/Hyena/Hyena.Collections/Selection.cs
@@ -52,9 +52,10 @@ namespace Hyena.Collections
RangeCollection ranges = new RangeCollection ();
private int max_index;
private int first_selected_index;
- private int focused_index = -1;
public event EventHandler Changed;
+ public event EventHandler FocusChanged;
+ private int focused_index = -1;
public Selection ()
{
@@ -62,7 +63,13 @@ namespace Hyena.Collections
public int FocusedIndex {
get { return focused_index; }
- set { focused_index = value; }
+ set {
+ focused_index = value;
+ var handler = FocusChanged;
+ if (handler != null) {
+ handler (this, EventArgs.Empty);
+ }
+ }
}
protected virtual void OnChanged ()
@@ -142,6 +149,19 @@ namespace Hyena.Collections
OnChanged ();
}
+ public void UnselectRange (int a, int b)
+ {
+ int start = Math.Min (a, b);
+ int end = Math.Max (a, b);
+
+ int i;
+ for (i = start; i <= end; i++) {
+ ranges.Remove (i);
+ }
+
+ OnChanged ();
+ }
+
public virtual void SelectAll ()
{
SelectRange (0, max_index);
@@ -183,7 +203,7 @@ namespace Hyena.Collections
}
}
- protected RangeCollection RangeCollection {
+ public RangeCollection RangeCollection {
get { return ranges; }
}
diff --git a/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs b/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs
index 594935b..146acb6 100644
--- a/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs
+++ b/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs
@@ -67,18 +67,17 @@ namespace Hyena.Json.Tests
[Test]
public void NumberInt ()
{
- // Number tests
- AssertTokenStream ("0", Token.Number (0));
- AssertTokenStream ("-0", Token.Number (-0));
+ AssertTokenStream ("0", Token.Integer (0));
+ AssertTokenStream ("-0", Token.Integer (-0));
- AssertTokenStream ("9", Token.Number (9));
- AssertTokenStream ("-9", Token.Number (-9));
+ AssertTokenStream ("9", Token.Integer (9));
+ AssertTokenStream ("-9", Token.Integer (-9));
- AssertTokenStream ("14", Token.Number (14));
- AssertTokenStream ("-14", Token.Number (-14));
+ AssertTokenStream ("14", Token.Integer (14));
+ AssertTokenStream ("-14", Token.Integer (-14));
- AssertTokenStream ("15309", Token.Number (15309));
- AssertTokenStream ("-15309", Token.Number (-15309));
+ AssertTokenStream ("15309", Token.Integer (15309));
+ AssertTokenStream ("-15309", Token.Integer (-15309));
}
[Test]
@@ -148,14 +147,14 @@ namespace Hyena.Json.Tests
[Test]
public void Array ()
{
- AssertTokenStream ("[1]", Token.ArrayStart, Token.Number (1), Token.ArrayFinish);
- AssertTokenStream ("[1,0]", Token.ArrayStart, Token.Number (1), Token.Comma, Token.Number (0), Token.ArrayFinish);
+ AssertTokenStream ("[1]", Token.ArrayStart, Token.Integer (1), Token.ArrayFinish);
+ AssertTokenStream ("[1,0]", Token.ArrayStart, Token.Integer (1), Token.Comma, Token.Integer (0), Token.ArrayFinish);
AssertTokenStream ("[\"a\",true,null]", Token.ArrayStart, Token.String ("a"), Token.Comma,
Token.Bool (true), Token.Comma, Token.Null, Token.ArrayFinish);
- AssertTokenStream ("[0,1,[[2,[4]],5],6]", Token.ArrayStart, Token.Number (0), Token.Comma, Token.Number (1),
- Token.Comma, Token.ArrayStart, Token.ArrayStart, Token.Number (2), Token.Comma, Token.ArrayStart,
- Token.Number (4), Token.ArrayFinish, Token.ArrayFinish, Token.Comma, Token.Number (5), Token.ArrayFinish,
- Token.Comma, Token.Number (6), Token.ArrayFinish);
+ AssertTokenStream ("[0,1,[[2,[4]],5],6]", Token.ArrayStart, Token.Integer (0), Token.Comma, Token.Integer (1),
+ Token.Comma, Token.ArrayStart, Token.ArrayStart, Token.Integer (2), Token.Comma, Token.ArrayStart,
+ Token.Integer (4), Token.ArrayFinish, Token.ArrayFinish, Token.Comma, Token.Integer (5), Token.ArrayFinish,
+ Token.Comma, Token.Integer (6), Token.ArrayFinish);
}
[Test]
@@ -194,7 +193,8 @@ namespace Hyena.Json.Tests
continue;
}
- if ((compare.Type == TokenType.Number && (double)compare.Value != (double)token.Value) ||
+ if ((compare.Type == TokenType.Integer && (int)compare.Value != (int)token.Value) ||
+ (compare.Type == TokenType.Number && (double)compare.Value != (double)token.Value) ||
(compare.Type == TokenType.String && (string)compare.Value != (string)token.Value) ||
(compare.Type == TokenType.Boolean && (bool)compare.Value != (bool)token.Value)) {
throw new ApplicationException ("Token values do not match");
diff --git a/src/Hyena/Hyena.Json/Token.cs b/src/Hyena/Hyena.Json/Token.cs
index e2b5ef2..4f9de6f 100644
--- a/src/Hyena/Hyena.Json/Token.cs
+++ b/src/Hyena/Hyena.Json/Token.cs
@@ -98,6 +98,11 @@ namespace Hyena.Json
return new Token (TokenType.Number, value);
}
+ internal static Token Integer (int value)
+ {
+ return new Token (TokenType.Integer, value);
+ }
+
internal static Token String (string value)
{
return new Token (TokenType.String, value);
diff --git a/src/Hyena/Hyena.Json/TokenType.cs b/src/Hyena/Hyena.Json/TokenType.cs
index 052631b..09b14a7 100644
--- a/src/Hyena/Hyena.Json/TokenType.cs
+++ b/src/Hyena/Hyena.Json/TokenType.cs
@@ -42,10 +42,11 @@ namespace Hyena.Json
String = 1 << 5,
Null = 1 << 6,
Number = 1 << 7,
- Comma = 1 << 8,
- Colon = 1 << 9,
+ Integer = 1 << 8,
+ Comma = 1 << 9,
+ Colon = 1 << 10,
- Literal = String | Number | Boolean | Null,
+ Literal = String | Number | Boolean | Null | Integer,
Value = ObjectStart | ArrayStart | Literal
}
}
diff --git a/src/Hyena/Hyena.Json/Tokenizer.cs b/src/Hyena/Hyena.Json/Tokenizer.cs
index 3210b11..90d1dd4 100644
--- a/src/Hyena/Hyena.Json/Tokenizer.cs
+++ b/src/Hyena/Hyena.Json/Tokenizer.cs
@@ -163,14 +163,14 @@ namespace Hyena.Json
return buffer.ToString ();
}
- private double LexInt ()
+ private int LexInt ()
{
return LexInt (false, 0);
}
- private double LexInt (bool hex, int maxDigits)
+ private int LexInt (bool hex, int maxDigits)
{
- double value = 0.0;
+ int value = 0;
int count = 0;
do {
@@ -212,34 +212,38 @@ namespace Hyena.Json
return fraction;
}
- private double LexNumber ()
+ private object LexNumber (out bool isDouble)
{
- double value = 0.0;
+ isDouble = false;
+ int intVal = 0;
+ double doubleVal = 0.0;
bool negate = peek == '-';
if (negate) {
ReadChar ();
}
if (peek != '0') {
- value = LexInt ();
+ doubleVal = intVal = LexInt ();
} else {
ReadChar ();
}
if (peek == '.') {
- value += LexFraction ();
+ isDouble = true;
+ doubleVal += LexFraction ();
}
if (peek == 'e' || peek == 'E') {
+ isDouble = true;
ReadChar ();
if (peek == '-') {
ReadChar ();
- value /= Math.Pow (10, LexInt ());
+ doubleVal /= Math.Pow (10, LexInt ());
} else if (peek == '+') {
ReadChar ();
- value *= Math.Pow (10, LexInt ());
+ doubleVal *= Math.Pow (10, LexInt ());
} else if (Char.IsDigit (peek)) {
- value *= Math.Pow (10, LexInt ());
+ doubleVal *= Math.Pow (10, LexInt ());
} else {
InvalidSyntax ("Malformed exponent");
}
@@ -250,7 +254,10 @@ namespace Hyena.Json
"followed by a digit (octal syntax not legal)");
}
- return negate ? -1.0 * value : value;
+ if (!isDouble)
+ return negate ? -1 * intVal : intVal;
+ else
+ return negate ? -1.0 * doubleVal : doubleVal;
}
public Token Scan ()
@@ -291,7 +298,12 @@ namespace Hyena.Json
case '"': return new Token (TokenType.String, LexString ());
default:
if (peek == '-' || Char.IsDigit (peek)) {
- return new Token (TokenType.Number, LexNumber ());
+ bool isDouble;
+ object num = LexNumber (out isDouble);
+ if (!isDouble)
+ return new Token (TokenType.Integer, num);
+ else
+ return new Token (TokenType.Number, num);
} else if (Char.IsLetter (peek)) {
string identifier = LexId ();
switch (identifier) {
diff --git a/src/Hyena/Hyena.Query/AliasedObjectSet.cs b/src/Hyena/Hyena.Query/AliasedObjectSet.cs
index e3533b9..ba8ad48 100644
--- a/src/Hyena/Hyena.Query/AliasedObjectSet.cs
+++ b/src/Hyena/Hyena.Query/AliasedObjectSet.cs
@@ -53,10 +53,12 @@ namespace Hyena.Query
map [obj.Name.ToLower ()] = obj;
foreach (string alias in obj.Aliases) {
if (!String.IsNullOrEmpty (alias) && alias.IndexOf (" ") == -1) {
- string lower_alias = alias.ToLower ();
- map [lower_alias] = obj;
- if (!aliases.Contains (lower_alias)) {
- aliases.Add (lower_alias);
+ foreach (string sub_alias in alias.Split(',')) {
+ string lower_alias = sub_alias.ToLower ();
+ map [lower_alias] = obj;
+ if (!aliases.Contains (lower_alias)) {
+ aliases.Add (lower_alias);
+ }
}
}
}
@@ -73,7 +75,7 @@ namespace Hyena.Query
{
input = input.ToLower ();
foreach (string alias in aliases) {
- if (input.Contains (alias)) {
+ if (input.StartsWith (alias)) {
return alias;
}
}
diff --git a/src/Hyena/Hyena.Query/QueryTermNode.cs b/src/Hyena/Hyena.Query/QueryTermNode.cs
index 42ff2ba..27c50ab 100644
--- a/src/Hyena/Hyena.Query/QueryTermNode.cs
+++ b/src/Hyena/Hyena.Query/QueryTermNode.cs
@@ -48,11 +48,12 @@ namespace Hyena.Query
string field_alias = field_set.FindAlias (token);
if (field_alias != null) {
term.Field = field_set [field_alias];
+ string token_without_field = token.Substring (field_alias.Length);
foreach (QueryValue val in term.Field.CreateQueryValues ()) {
term.Value = val;
- string op_alias = term.Value.OperatorSet.FindAlias (token);
+ string op_alias = term.Value.OperatorSet.FindAlias (token_without_field);
if (op_alias != null) {
term.Operator = term.Value.OperatorSet [op_alias];
int field_separator = token.IndexOf (op_alias);
diff --git a/src/Hyena/Hyena.Query/Tests/QueryTests.cs b/src/Hyena/Hyena.Query/Tests/QueryTests.cs
index 1421288..ceb5c29 100644
--- a/src/Hyena/Hyena.Query/Tests/QueryTests.cs
+++ b/src/Hyena/Hyena.Query/Tests/QueryTests.cs
@@ -141,6 +141,8 @@ namespace Hyena.Query.Tests
"by:baz -on:bar",
"by:baz -on:bar",
"by:baz (plays>3 or plays<2)",
+ "by:on", // bgo#601065
+ "on:by",
};
AssertForEach<string> (tests, UserQueryParsesAndGenerates);
diff --git a/src/Hyena/Hyena/StringUtil.cs b/src/Hyena/Hyena/StringUtil.cs
index a4d44db..8de7d3b 100644
--- a/src/Hyena/Hyena/StringUtil.cs
+++ b/src/Hyena/Hyena/StringUtil.cs
@@ -185,11 +185,11 @@ namespace Hyena
val = val.ToLower ();
StringBuilder sb = new StringBuilder ();
UnicodeCategory category;
- bool previous_was_latin = false;
+ bool previous_was_letter = false;
bool got_space = false;
- // Normalizing to KD splits into (base, combining) so we can check for Latin
- // characters and then strip off any NonSpacingMarks following them
+ // Normalizing to KD splits into (base, combining) so we can check for letters
+ // and then strip off any NonSpacingMarks following them
foreach (char orig_c in val.TrimStart ().Normalize (NormalizationForm.FormKD)) {
// Check for a special case *before* whitespace. This way, if
@@ -208,7 +208,7 @@ namespace Hyena
category = Char.GetUnicodeCategory (c);
if (category == UnicodeCategory.OtherPunctuation) {
// Skip punctuation
- } else if (!(previous_was_latin && category == UnicodeCategory.NonSpacingMark)) {
+ } else if (!(previous_was_letter && category == UnicodeCategory.NonSpacingMark)) {
if (got_space) {
sb.Append (" ");
got_space = false;
@@ -217,10 +217,17 @@ namespace Hyena
}
// Can ignore A-Z because we've already lowercased the char
- previous_was_latin = (c >= 'a' && c <= 'z');
+ previous_was_letter = Char.IsLetter (c);
}
- return sb.ToString ().Normalize (NormalizationForm.FormKC);
+ string result = sb.ToString ();
+ try {
+ result = result.Normalize (NormalizationForm.FormKC);
+ }
+ catch {
+ // FIXME: work-around, see http://bugzilla.gnome.org/show_bug.cgi?id=590478
+ }
+ return result;
}
private static Regex invalid_path_regex = BuildInvalidPathRegex ();
diff --git a/src/Hyena/Hyena/Tests/StringUtilTests.cs b/src/Hyena/Hyena/Tests/StringUtilTests.cs
index de38010..ecf331e 100644
--- a/src/Hyena/Hyena/Tests/StringUtilTests.cs
+++ b/src/Hyena/Hyena/Tests/StringUtilTests.cs
@@ -128,13 +128,8 @@ namespace Hyena.Tests
Assert.AreEqual (null, StringUtil.RemoveNewlines (null));
Assert.AreEqual ("foobar", StringUtil.RemoveNewlines (@"foo
bar"));
- Assert.AreEqual ("foobar baz", StringUtil.RemoveNewlines (@"foo
-bar
-baz"));
- Assert.AreEqual ("haswindows newline andunix", StringUtil.RemoveNewlines (@"has
-windows
- newline
-andunix"));
+ Assert.AreEqual ("foobar baz", StringUtil.RemoveNewlines ("foo\nbar \nbaz"));
+ Assert.AreEqual ("haswindows newline andunix", StringUtil.RemoveNewlines ("has\nwindows\r\n newline \nandunix"));
}
[Test]
@@ -208,14 +203,15 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertSearchKey ("Ź", "z");
AssertSearchKey ("ż", "z");
AssertSearchKey ("Å»", "z");
- }
- // Test that combining diacritics are preserved, and combined, for non-Latin characters.
- [Test]
- public void TestPreserveDiacritics ()
- {
- AssertSearchKey ("\u304c", "\u304c");
- AssertSearchKey ("\u304b\u3099", "\u304c");
+ // Hiragana
+ AssertSearchKey ("\u304c", "\u304b");
+
+ // Cyrillic
+ AssertSearchKey ("\u0451", "\u0435");
+ AssertSearchKey ("\u0401", "\u0435");
+ AssertSearchKey ("\u0439", "\u0438");
+ AssertSearchKey ("\u0419", "\u0438");
}
// Test that some non-Latin characters are converted to Latin counterparts.
diff --git a/src/Hyena/Hyena/ThreadAssist.cs b/src/Hyena/Hyena/ThreadAssist.cs
index dd9d14b..c685046 100644
--- a/src/Hyena/Hyena/ThreadAssist.cs
+++ b/src/Hyena/Hyena/ThreadAssist.cs
@@ -72,10 +72,28 @@ namespace Hyena
}
}
+ public static void BlockingProxyToMain (InvokeHandler handler)
+ {
+ if (!InMainThread) {
+ var reset_event = new System.Threading.ManualResetEvent (false);
+
+ ProxyToMainHandler (delegate {
+ try {
+ handler ();
+ } finally {
+ reset_event.Set ();
+ }
+ });
+
+ reset_event.WaitOne ();
+ } else {
+ handler ();
+ }
+ }
+
public static void ProxyToMain (InvokeHandler handler)
{
if (!InMainThread) {
- //Banshee.ServiceStack.Application.Invoke (handler);
ProxyToMainHandler (handler);
} else {
handler ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]