1. Shlomi Fish
  2. perl-XML-LibXML

Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed 5927295

Modified Files:
LibXML.pm
+ two new functions:
XML::LibXML::Text::replaceDataString($old, $new)
replaces the first occurrence of $old with $new
XML::LibXML::Text::replaceDataRE($lre,$rre, $all)
will create "s/$lre/$rre/" unless $all
or "s/$lre/$rre/g" otherwise and applies this to the
current textnode's data.

  • Participants
  • Parent commits c02ab6c
  • Branches default

Comments (0)

Files changed (1)

File LibXML.pm

View file
     $pi->_setData( $string ) unless  $string =~ /\?>/;
 }
 
+sub XML::LibXML::Text::replaceDataString {
+    my ( $node, $left, $right ) = @_;
+
+    #ashure we exchange the strings and not expressions!
+    $left  =~ s/([\\\*\+\^\{\}\&\?\[\]\(\)\$\%\@])/\$1/g;
+    $right =~ s/([\\\*\+\^\{\}\&\?\[\]\(\)\$\%\@])/\$1/g;
+    my $datastr = $node->getData();
+    $datastr =~ s/$left/$right/;
+    $node->setData( $datastr );
+}
+
+sub XML::LibXML::Text::replaceDataRE {
+    my ( $node, $leftre, $rightre, $flag_all ) = @_;
+    return unless defined $leftre;
+    $rightre ||= "";
+
+    my $datastr = $node->getData();
+    my $restr   = "s/" . $leftre . "/" . $rightre . "/";
+    $restr .= "g" if defined $flag_all and $flag_all == 1;
+
+    eval "\$datastring =~ $restr";
+    $node->setData( $datastr );
+}
+
 1;
 __END__
 
 
 =head1 PARSING
 
-There are three ways to parse documents - as a string, as a Perl filehandle,
-or as a filename. The return value from each is a XML::LibXML::Document
-object, which is a DOM object (although no DOM methods are implemented
-yet). See L<"XML::LibXML::Document"> below for more details on the methods
-available on documents.
+There are three ways to parse documents - as a string, as a Perl
+filehandle, or as a filename. The return value from each is a
+XML::LibXML::Document object, which is a DOM object (although not all
+DOM methods are implemented yet). See L<"XML::LibXML::Document"> below
+for more details on the methods available on documents.
 
 Each of the below methods will throw an exception if the document is invalid.
 To prevent this causing your program exiting, wrap the call in an eval{}