/[suikacvs]/messaging/manakai/lib/Message/DOM/StringExtended.pm
Suika

Contents of /messaging/manakai/lib/Message/DOM/StringExtended.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Sun Jul 8 09:25:17 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
CVS Tags: manakai-release-0-4-0, HEAD
Error occurred while calculating annotation data.
++ manakai/t/ChangeLog	8 Jul 2007 09:25:11 -0000
	* DOM-StringExtended.t: New test script.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	8 Jul 2007 09:24:53 -0000
	* StringExtended.pm: New Perl module.

	* DOMCharacterData.pm (length, append_data, delete_data,
	insert_data, replace_data, substring_data): Implemented.

	* DOMException.pm (INDEX_SIZE_ERR): Implemented.

	* Text.pm (is_element_content_whitespace, whole_text,
	split_text): Implemented.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

1 package Message::DOM::StringExtended;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 push our @ISA, 'Message::IF::StringExtended', 'Exporter';
5 require Exporter;
6 our @EXPORT_OK = qw(find_offset16 find_offset32);
7
8 sub find_offset16 ($$) {
9 my $v = ''.$_[0];
10 my $offset32 = 0+$_[1];
11
12 if ($offset32 < 0 or length $v < $offset32) {
13 require Carp;
14 Carp::croak ("String index out of bounds");
15 }
16
17 my $ss = substr $v, 0, $offset32;
18 my $r = $offset32;
19 if ($ss =~ /[\x{10000}-\x{10FFFF}]/) {
20 while ($ss =~ /[\x{10000}-\x{10FFFF}]+/g) {
21 $r += $+[0] - $-[0];
22 }
23 }
24
25 return $r;
26 } # find_offset16
27
28 sub find_offset32 ($$) {
29 my $v = ''.$_[0];
30 my $offset16 = 0+$_[1];
31
32 if ($offset16 < 0) {
33 require Carp;
34 Carp::croak ("String index out of bounds");
35 }
36
37 my $r = 0;
38 my $o = $offset16;
39 while ($o > 0) {
40 my $c = substr ($v, $r, 1);
41 if (length $c) {
42 if ($c =~ /[\x{10000}-\x{10FFFF}]/) {
43 $o -= 2;
44 } else {
45 $o--;
46 }
47 $r++;
48 } else {
49 require Carp;
50 Carp::croak ("String index out of bounds");
51 }
52 }
53
54 return $r;
55 } # find_offset32
56
57 package Message::IF::StringExtended;
58
59 =head1 LICENSE
60
61 Copyright 2007 Wakaba <w@suika.fam.cx>
62
63 This program is free software; you can redistribute it and/or
64 modify it under the same terms as Perl itself.
65
66 =cut
67
68 1;
69 ## $Date: 2007/07/08 05:42:37 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24