Permalink
Browse files

merge in patch from PEAR bug #10620: use \z instead of $ in regexes

git-svn-id: http://svn.php.net/repository/pear/packages/XML_Util/trunk@275418 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent b437815 commit 42715d468d09534cf382a2dd42d2c51758cd8e01 Chuck Burgess committed Feb 9, 2009
Showing with 59 additions and 59 deletions.
  1. +59 −59 Util.php
View
@@ -6,7 +6,7 @@
* XML_Util
*
* XML Utilities package
- *
+ *
* PHP versions 4 and 5
*
* LICENSE:
@@ -161,11 +161,11 @@ function apiVersion()
* );
* </code>
*
- * @param string $string string where XML special chars
+ * @param string $string string where XML special chars
* should be replaced
- * @param int $replaceEntities setting for entities in attribute values
- * (one of XML_UTIL_ENTITIES_XML,
- * XML_UTIL_ENTITIES_XML_REQUIRED,
+ * @param int $replaceEntities setting for entities in attribute values
+ * (one of XML_UTIL_ENTITIES_XML,
+ * XML_UTIL_ENTITIES_XML_REQUIRED,
* XML_UTIL_ENTITIES_HTML)
* @param string $encoding encoding value (if any)...
* must be a valid encoding as determined
@@ -227,11 +227,11 @@ function replaceEntities($string, $replaceEntities = XML_UTIL_ENTITIES_XML,
* );
* </code>
*
- * @param string $string string where XML special chars
+ * @param string $string string where XML special chars
* should be replaced
- * @param int $replaceEntities setting for entities in attribute values
- * (one of XML_UTIL_ENTITIES_XML,
- * XML_UTIL_ENTITIES_XML_REQUIRED,
+ * @param int $replaceEntities setting for entities in attribute values
+ * (one of XML_UTIL_ENTITIES_XML,
+ * XML_UTIL_ENTITIES_XML_REQUIRED,
* XML_UTIL_ENTITIES_HTML)
* @param string $encoding encoding value (if any)...
* must be a valid encoding as determined
@@ -286,7 +286,7 @@ function reverseEntities($string, $replaceEntities = XML_UTIL_ENTITIES_XML,
* @static
* @uses attributesToString() to serialize the attributes of the XML declaration
*/
- function getXMLDeclaration($version = '1.0', $encoding = null,
+ function getXMLDeclaration($version = '1.0', $encoding = null,
$standalone = null)
{
$attributes = array(
@@ -301,7 +301,7 @@ function getXMLDeclaration($version = '1.0', $encoding = null,
$attributes['standalone'] = $standalone ? 'yes' : 'no';
}
- return sprintf('<?xml%s?>',
+ return sprintf('<?xml%s?>',
XML_Util::attributesToString($attributes, false));
}
@@ -316,7 +316,7 @@ function getXMLDeclaration($version = '1.0', $encoding = null,
* </code>
*
* @param string $root name of the root tag
- * @param string $uri uri of the doctype definition
+ * @param string $uri uri of the doctype definition
* (or array with uri and public id)
* @param string $internalDtd internal dtd entries
*
@@ -358,20 +358,20 @@ function getDocTypeDeclaration($root, $uri = null, $internalDtd = null)
* </code>
*
* @param array $attributes attribute array
- * @param bool|array $sort sort attribute list alphabetically,
- * may also be an assoc array containing
- * the keys 'sort', 'multiline', 'indent',
+ * @param bool|array $sort sort attribute list alphabetically,
+ * may also be an assoc array containing
+ * the keys 'sort', 'multiline', 'indent',
* 'linebreak' and 'entities'
- * @param bool $multiline use linebreaks, if more than
+ * @param bool $multiline use linebreaks, if more than
* one attribute is given
- * @param string $indent string used for indentation of
+ * @param string $indent string used for indentation of
* multiline attributes
- * @param string $linebreak string used for linebreaks of
+ * @param string $linebreak string used for linebreaks of
* multiline attributes
- * @param int $entities setting for entities in attribute values
- * (one of XML_UTIL_ENTITIES_NONE,
- * XML_UTIL_ENTITIES_XML,
- * XML_UTIL_ENTITIES_XML_REQUIRED,
+ * @param int $entities setting for entities in attribute values
+ * (one of XML_UTIL_ENTITIES_NONE,
+ * XML_UTIL_ENTITIES_XML,
+ * XML_UTIL_ENTITIES_XML_REQUIRED,
* XML_UTIL_ENTITIES_HTML)
*
* @return string string representation of the attributes
@@ -380,7 +380,7 @@ function getDocTypeDeclaration($root, $uri = null, $internalDtd = null)
* @uses replaceEntities() to replace XML entities in attribute values
* @todo allow sort also to be an options array
*/
- function attributesToString($attributes, $sort = true, $multiline = false,
+ function attributesToString($attributes, $sort = true, $multiline = false,
$indent = ' ', $linebreak = "\n", $entities = XML_UTIL_ENTITIES_XML)
{
/*
@@ -451,7 +451,7 @@ function attributesToString($attributes, $sort = true, $multiline = false,
* @todo PEAR CS - unable to avoid "space after open parens" error
* in the IF branch
*/
- function collapseEmptyTags($xml, $mode = XML_UTIL_COLLAPSE_ALL)
+ function collapseEmptyTags($xml, $mode = XML_UTIL_COLLAPSE_ALL)
{
if ($mode == XML_UTIL_COLLAPSE_XHTML_ONLY) {
return preg_replace(
@@ -474,23 +474,23 @@ function collapseEmptyTags($xml, $mode = XML_UTIL_COLLAPSE_ALL)
* require_once 'XML/Util.php';
*
* // create an XML tag:
- * $tag = XML_Util::createTag('myNs:myTag',
- * array('foo' => 'bar'),
- * 'This is inside the tag',
+ * $tag = XML_Util::createTag('myNs:myTag',
+ * array('foo' => 'bar'),
+ * 'This is inside the tag',
* 'http://www.w3c.org/myNs#');
* </code>
*
* @param string $qname qualified tagname (including namespace)
* @param array $attributes array containg attributes
* @param mixed $content the content
* @param string $namespaceUri URI of the namespace
- * @param int $replaceEntities whether to replace XML special chars in
- * content, embedd it in a CData section
+ * @param int $replaceEntities whether to replace XML special chars in
+ * content, embedd it in a CData section
* or none of both
- * @param bool $multiline whether to create a multiline tag where
+ * @param bool $multiline whether to create a multiline tag where
* each attribute gets written to a single line
- * @param string $indent string used to indent attributes
- * (_auto indents attributes so they start
+ * @param string $indent string used to indent attributes
+ * (_auto indents attributes so they start
* at the same column)
* @param string $linebreak string used for linebreaks
* @param bool $sortAttributes Whether to sort the attributes or not
@@ -501,9 +501,9 @@ function collapseEmptyTags($xml, $mode = XML_UTIL_COLLAPSE_ALL)
* @see createTagFromArray()
* @uses createTagFromArray() to create the tag
*/
- function createTag($qname, $attributes = array(), $content = null,
- $namespaceUri = null, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
- $multiline = false, $indent = '_auto', $linebreak = "\n",
+ function createTag($qname, $attributes = array(), $content = null,
+ $namespaceUri = null, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
+ $multiline = false, $indent = '_auto', $linebreak = "\n",
$sortAttributes = true)
{
$tag = array(
@@ -521,7 +521,7 @@ function createTag($qname, $attributes = array(), $content = null,
$tag['namespaceUri'] = $namespaceUri;
}
- return XML_Util::createTagFromArray($tag, $replaceEntities, $multiline,
+ return XML_Util::createTagFromArray($tag, $replaceEntities, $multiline,
$indent, $linebreak, $sortAttributes);
}
@@ -531,22 +531,22 @@ function createTag($qname, $attributes = array(), $content = null,
* <pre>
* array(
* // qualified name of the tag
- * 'qname' => $qname
+ * 'qname' => $qname
*
* // namespace prefix (optional, if qname is specified or no namespace)
- * 'namespace' => $namespace
+ * 'namespace' => $namespace
*
* // local part of the tagname (optional, if qname is specified)
- * 'localpart' => $localpart,
+ * 'localpart' => $localpart,
*
* // array containing all attributes (optional)
- * 'attributes' => array(),
+ * 'attributes' => array(),
*
* // tag content (optional)
- * 'content' => $content,
+ * 'content' => $content,
*
* // namespaceUri for the given namespace (optional)
- * 'namespaceUri' => $namespaceUri
+ * 'namespaceUri' => $namespaceUri
* )
* </pre>
*
@@ -564,13 +564,13 @@ function createTag($qname, $attributes = array(), $content = null,
* </code>
*
* @param array $tag tag definition
- * @param int $replaceEntities whether to replace XML special chars in
- * content, embedd it in a CData section
+ * @param int $replaceEntities whether to replace XML special chars in
+ * content, embedd it in a CData section
* or none of both
- * @param bool $multiline whether to create a multiline tag where each
+ * @param bool $multiline whether to create a multiline tag where each
* attribute gets written to a single line
- * @param string $indent string used to indent attributes
- * (_auto indents attributes so they start
+ * @param string $indent string used to indent attributes
+ * (_auto indents attributes so they start
* at the same column)
* @param string $linebreak string used for linebreaks
* @param bool $sortAttributes Whether to sort the attributes or not
@@ -585,7 +585,7 @@ function createTag($qname, $attributes = array(), $content = null,
* @uses raiseError()
*/
function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
- $multiline = false, $indent = '_auto', $linebreak = "\n",
+ $multiline = false, $indent = '_auto', $linebreak = "\n",
$sortAttributes = true)
{
if (isset($tag['content']) && !is_scalar($tag['content'])) {
@@ -595,7 +595,7 @@ function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
if (!isset($tag['qname']) && !isset($tag['localPart'])) {
return XML_Util::raiseError('You must either supply a qualified name '
- . '(qname) or local tag name (localPart).',
+ . '(qname) or local tag name (localPart).',
XML_UTIL_ERROR_NO_TAG_NAME);
}
@@ -649,7 +649,7 @@ function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
}
// create attribute list
- $attList = XML_Util::attributesToString($tag['attributes'],
+ $attList = XML_Util::attributesToString($tag['attributes'],
$sortAttributes, $multiline, $indent, $linebreak, $replaceEntities);
if (!isset($tag['content']) || (string)$tag['content'] == '') {
$tag = sprintf('<%s%s />', $tag['qname'], $attList);
@@ -661,7 +661,7 @@ function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
$tag['content'] = XML_Util::createCDataSection($tag['content']);
break;
default:
- $tag['content'] = XML_Util::replaceEntities($tag['content'],
+ $tag['content'] = XML_Util::replaceEntities($tag['content'],
$replaceEntities);
break;
}
@@ -678,14 +678,14 @@ function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
* require_once 'XML/Util.php';
*
* // create an XML start element:
- * $tag = XML_Util::createStartElement('myNs:myTag',
+ * $tag = XML_Util::createStartElement('myNs:myTag',
* array('foo' => 'bar') ,'http://www.w3c.org/myNs#');
* </code>
*
* @param string $qname qualified tagname (including namespace)
* @param array $attributes array containg attributes
* @param string $namespaceUri URI of the namespace
- * @param bool $multiline whether to create a multiline tag where each
+ * @param bool $multiline whether to create a multiline tag where each
* attribute gets written to a single line
* @param string $indent string used to indent attributes (_auto indents
* attributes so they start at the same column)
@@ -698,7 +698,7 @@ function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
* @see createEndElement(), createTag()
*/
function createStartElement($qname, $attributes = array(), $namespaceUri = null,
- $multiline = false, $indent = '_auto', $linebreak = "\n",
+ $multiline = false, $indent = '_auto', $linebreak = "\n",
$sortAttributes = true)
{
// if no attributes hav been set, use empty attributes
@@ -728,7 +728,7 @@ function createStartElement($qname, $attributes = array(), $namespaceUri = null,
}
// create attribute list
- $attList = XML_Util::attributesToString($attributes, $sortAttributes,
+ $attList = XML_Util::attributesToString($attributes, $sortAttributes,
$multiline, $indent, $linebreak);
$element = sprintf('<%s%s>', $qname, $attList);
return $element;
@@ -797,7 +797,7 @@ function createComment($content)
*/
function createCDataSection($data)
{
- return sprintf('<![CDATA[%s]]>',
+ return sprintf('<![CDATA[%s]]>',
preg_replace('/\]\]>/', ']]]]><![CDATA[>', strval($data)));
}
@@ -871,17 +871,17 @@ function splitQualifiedName($qname, $defaultNs = null)
function isValidName($string)
{
// check for invalid chars
- if (!preg_match('/^[[:alpha:]_]$/', $string{0})) {
+ if (!preg_match('/^[[:alpha:]_]\\z/', $string{0})) {
return XML_Util::raiseError('XML names may only start with letter '
. 'or underscore', XML_UTIL_ERROR_INVALID_START);
}
// check for invalid chars
- if (!preg_match('/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?$/',
+ if (!preg_match('/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?\\z/',
$string)
) {
return XML_Util::raiseError('XML names may only contain alphanumeric '
- . 'chars, period, hyphen, colon and underscores',
+ . 'chars, period, hyphen, colon and underscores',
XML_UTIL_ERROR_INVALID_CHARS);
}
// XML name is valid

0 comments on commit 42715d4

Please sign in to comment.