projects
/
m17n
/
m17n-lib-cs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
18fc769
)
*** empty log message ***
author
handa
<handa>
Fri, 3 Apr 2009 12:15:30 +0000
(12:15 +0000)
committer
handa
<handa>
Fri, 3 Apr 2009 12:15:30 +0000
(12:15 +0000)
MPlist.cs
patch
|
blob
|
history
MText.cs
patch
|
blob
|
history
diff --git
a/MPlist.cs
b/MPlist.cs
index
0b077a4
..
ca6022a
100644
(file)
--- a/
MPlist.cs
+++ b/
MPlist.cs
@@
-56,7
+56,7
@@
namespace M17N.Core
return str + ")";
}
return str + ")";
}
- public MPlist Find (MSymbol key)
+ private MPlist find (MSymbol key)
{
MPlist p;
{
MPlist p;
@@
-66,9
+66,16
@@
namespace M17N.Core
return p;
}
return p;
}
+ public MPlist Find (MSymbol key)
+ {
+ MPlist p = find (key);
+
+ return (p.IsEmpty ? null : p);
+ }
+
public object Get (MSymbol key)
{
public object Get (MSymbol key)
{
- return Find (key).Val;
+ return find (key).Val;
}
public MPlist Set (MSymbol key, object val)
}
public MPlist Set (MSymbol key, object val)
@@
-82,7
+89,7
@@
namespace M17N.Core
public MPlist Put (MSymbol key, object val)
{
public MPlist Put (MSymbol key, object val)
{
- return Find (key).Set (key, val);
+ return find (key).Set (key, val);
}
public MPlist Push (MSymbol key, object val)
}
public MPlist Push (MSymbol key, object val)
diff --git
a/MText.cs
b/MText.cs
index
cfa688b
..
cbf5c8a
100644
(file)
--- a/
MText.cs
+++ b/
MText.cs
@@
-239,11
+239,12
@@
namespace M17N.Core
throw new Exception ("Invalid MText position:" + pos);
}
throw new Exception ("Invalid MText position:" + pos);
}
- private void check_range (int from, int to, bool zero_ok)
+ private bool check_range (int from, int to, bool zero_ok)
{
if (from < 0 || (zero_ok ? from > to : from >= to)
|| to > nchars)
throw new Exception ("Invalid MText range");
{
if (from < 0 || (zero_ok ? from > to : from >= to)
|| to > nchars)
throw new Exception ("Invalid MText range");
+ return (from == to);
}
private void insert (int pos, MText mt2, int from, int to)
}
private void insert (int pos, MText mt2, int from, int to)
@@
-265,7
+266,7
@@
namespace M17N.Core
MPlist p = mt2.intervals.Find (plist.Key);
MInterval interval;
MPlist p = mt2.intervals.Find (plist.Key);
MInterval interval;
- if (p.IsEmpty)
+ if (p == null)
interval = new MInterval (plist.Key, to - from);
else
interval = ((MInterval) p.Val).copy (from, to);
interval = new MInterval (plist.Key, to - from);
else
interval = ((MInterval) p.Val).copy (from, to);
@@
-321,7
+322,8
@@
namespace M17N.Core
public MText Del (int from, int to)
{
public MText Del (int from, int to)
{
- check_range (from, to, true);
+ if (check_range (from, to, true))
+ return this;
sb.Remove (from, pos_to_idx (this, to) - pos_to_idx (this, from));
nchars -= to - from;
sb.Remove (from, pos_to_idx (this, to) - pos_to_idx (this, from));
nchars -= to - from;
@@
-373,9
+375,8
@@
namespace M17N.Core
public void PushProp (int from, int to, MSymbol key, object val)
{
public void PushProp (int from, int to, MSymbol key, object val)
{
- check_range (from, to, false);
-
- PushProp (from, to, new MTextProperty (key, val));
+ if (! check_range (from, to, true))
+ PushProp (from, to, new MTextProperty (key, val));
}
public void PushProp (int from, int to, MTextProperty prop)
}
public void PushProp (int from, int to, MTextProperty prop)
@@
-388,17
+389,47
@@
namespace M17N.Core
}
else
{
}
else
{
- MInterval root = (MInterval) intervals.Find (prop.key).Val;
+ if (check_range (from, to, true))
+ return;
- if (root == null)
+ MPlist p = intervals.Find (prop.key);
+ MInterval root;
+
+ if (p == null)
{
root = new MInterval (prop.key, this);
intervals.Push (prop.key, root);
}
{
root = new MInterval (prop.key, this);
intervals.Push (prop.key, root);
}
+ else
+ root = (MInterval) p.Val;
+
root.Push (from, to, prop);
}
}
root.Push (from, to, prop);
}
}
+ public void PopProp (int from, int to, MSymbol key)
+ {
+ if (from < 0)
+ {
+ if (default_property == null)
+ return;
+ MPlist p = default_property.Find (key);
+
+ if (p != null)
+ p.Pop ();
+ }
+ else
+ {
+ if (check_range (from, to, true))
+ return;
+
+ MPlist p = intervals.Find (key);
+
+ if (p != null)
+ ((MInterval) p.Val).Pop (from, to);
+ }
+ }
+
public void DumpProp ()
{
Console.Write ("(");
public void DumpProp ()
{
Console.Write ("(");
@@
-744,7
+775,7
@@
namespace M17N.Core
if ((prop.flags & MTextProperty.Flag.RearSticky)
== MTextProperty.Flag.RearSticky)
if ((prop.flags & MTextProperty.Flag.RearSticky)
== MTextProperty.Flag.RearSticky)
- i.stack.Push (prop.key, prop);
+ i.stack.Add (prop.key, prop);
}
}
}
}
}
}
@@
-761,7
+792,7
@@
namespace M17N.Core
if ((prop.flags & MTextProperty.Flag.FrontSticky)
== MTextProperty.Flag.FrontSticky)
if ((prop.flags & MTextProperty.Flag.FrontSticky)
== MTextProperty.Flag.FrontSticky)
- i.stack.Push (prop.key, prop);
+ i.stack.Add (prop.key, prop);
}
}
}
}
}
}
@@
-974,6
+1005,41
@@
namespace M17N.Core
stack.Push (prop.key, prop);
}
stack.Push (prop.key, prop);
}
+ public void Pop (int start, int end)
+ {
+ update_from_to ();
+ Console.Write ("pop({0} {1}) at ", start, end); DumpOne (false, true);
+ if (start < from)
+ {
+ if (end <= from)
+ {
+ left.Pop (start, end);
+ return;
+ }
+ left.Pop (start, from);
+ start = from;
+ }
+ if (end > to)
+ {
+ if (start >= to)
+ {
+ right.Pop (start, end);
+ return;
+ }
+ right.Pop (to, end);
+ end = to;
+ }
+
+ if (! stack.IsEmpty)
+ {
+ if (start > from)
+ divide_left (start);
+ if (end < to)
+ divide_right (end);
+ stack.Pop ();
+ }
+ }
+
private void DumpOne (bool with_prop, bool newline)
{
Console.Write ("#{0}({1} {2} {3}", id, total_length, from, to);
private void DumpOne (bool with_prop, bool newline)
{
Console.Write ("#{0}({1} {2} {3}", id, total_length, from, to);