[gxml] Fixed GCharacterData's implementation of DomCharacterData.replace_data()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed GCharacterData's implementation of DomCharacterData.replace_data()
- Date: Fri, 22 Jul 2016 00:20:26 +0000 (UTC)
commit 165c7e562e223f86b64b60e3a811fbf87f597cba
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Jul 21 19:11:45 2016 -0500
Fixed GCharacterData's implementation of DomCharacterData.replace_data()
gxml/DomCharacter.vala | 10 +++-------
test/DomGDocumentTest.vala | 6 ++++++
2 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/gxml/DomCharacter.vala b/gxml/DomCharacter.vala
index 284d56a..f6ba13a 100644
--- a/gxml/DomCharacter.vala
+++ b/gxml/DomCharacter.vala
@@ -55,13 +55,9 @@ public interface GXml.DomCharacterData : GLib.Object,
public new virtual void replace_data (ulong offset, ulong count, string data) throws GLib.Error {
if (((int)offset) > this.data.length)
throw new DomError.INDEX_SIZE_ERROR (_("Invalid offset for replace data"));
- int c = (int) count;
- if (((int)offset + c) > data.length) c = data.length - (int)offset;
-
- string s = this.data[0:(int)offset];
- string s2 = this.data[0:(s.length - (int)offset - c)];
- string sr = data[0:(int)count];
- this.data = (s+sr+s2).dup ();
+ int end = (int) (offset + count);
+ if (!(end < this.data.length)) end = this.data.length;
+ this.data = this.data.splice ((int) offset, end, data);
}
}
diff --git a/test/DomGDocumentTest.vala b/test/DomGDocumentTest.vala
index da129cc..48e3264 100644
--- a/test/DomGDocumentTest.vala
+++ b/test/DomGDocumentTest.vala
@@ -498,6 +498,12 @@ static const string XMLDOC ="<?xml version=\"1.0\"?>
assert_not_reached ();
}
catch {}
+ t.append_data (" HI");
+ assert (t.data == "TEXT HI");
+ GLib.message ("t = "+t.substring_data (0, 4));
+ t.replace_data (0, 4, "");
+ GLib.message ("Text:'"+t.data+"'");
+ assert (t.data == " HI");
} catch (GLib.Error e) {
GLib.message ("Error: "+ e.message);
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]