Ejemplo n.º 1
0
 public function testFindGroups()
 {
     // ASCII.
     $foundGroups;
     $found = CRegex::findGroups("Hello there!", "/^(\\w+) (\\w+)/", $foundGroups);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CString::equals($foundGroups[0], "Hello") && CString::equals($foundGroups[1], "there"));
     $foundGroups;
     $foundString;
     $found = CRegex::findGroups("Hello there!", "/^(\\w+) (\\S+)/", $foundGroups, $foundString);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CString::equals($foundGroups[0], "Hello") && CString::equals($foundGroups[1], "there!") && CString::equals($foundString, "Hello there!"));
     $foundGroups;
     $this->assertFalse(CRegex::findGroups("Hello there!", "/^(\\w+) (\\w+)\\z/", $foundGroups));
     $foundGroups;
     $found = CRegex::findGroups("Hello there!", "/^\\w+ \\w+/", $foundGroups);
     $this->assertTrue($found && CArray::isEmpty($foundGroups));
     // Unicode.
     $foundGroups;
     $found = CRegex::findGroups("¡Hello señor!", "/(\\w+) (\\w+)/u", $foundGroups);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CUString::equals($foundGroups[0], "Hello") && CUString::equals($foundGroups[1], "señor"));
     $foundGroups;
     $foundString;
     $found = CRegex::findGroups("¡Hello señor!", "/(\\w+) (\\S+)/u", $foundGroups, $foundString);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CUString::equals($foundGroups[0], "Hello") && CUString::equals($foundGroups[1], "señor!") && CUString::equals($foundString, "Hello señor!"));
     $foundGroups;
     $this->assertFalse(CRegex::findGroups("¡Hello señor!", "/^(\\w+) (\\w+)/u", $foundGroups));
 }
Ejemplo n.º 2
0
 /**
  * @ignore
  */
 public function headerFunction($curl, $headerLine)
 {
     $ret = CString::length($headerLine);
     $foundGroups;
     if (CRegex::findGroups($headerLine, "/^\\s*(.+?)\\h*:\\h*(.*?)\\s*\\z/", $foundGroups)) {
         $this->addHeaderWithoutOverriding($this->m_responseHeaders, $foundGroups[0], $foundGroups[1]);
     }
     return $ret;
 }
Ejemplo n.º 3
0
 /**
  * Determines if a locale name is valid and known.
  *
  * Scripts, variants, and keyword-value pairs are ignored.
  *
  * @param  string $localeName The locale name to be looked into.
  *
  * @return bool `true` if the locale name is valid and known, `false` otherwise.
  */
 public static function isValid($localeName)
 {
     assert('is_cstring($localeName)', vs(isset($this), get_defined_vars()));
     if (!CRegex::findGroups($localeName, "/^([a-z]{2,3}(?![^_\\-]))(?|[_\\-]([a-z]{2,3}(?![^_\\-]))|[_\\-][a-z]{4}(?![^_\\-])[_\\-]([a-z]{2,3}" . "(?![^_\\-]))|(?:\\z|[_\\-][a-z])).*\\z(?<=[a-z0-9])/i", $foundGroups)) {
         return false;
     }
     $rfc2616 = $foundGroups[0];
     if (CArray::length($foundGroups) > 1) {
         $rfc2616 .= "-" . $foundGroups[1];
     }
     return is_cstring(Locale::acceptFromHttp($rfc2616));
 }
Ejemplo n.º 4
0
 /**
  * Determines if a string contains a specified regular expression pattern, putting every substring that matches a
  * regular expression group into an array for output and optionally reporting the substring that matched the
  * pattern.
  *
  * @param  string $findPattern The searched pattern, usually with groups.
  * @param  reference $foundGroups **OUTPUT.** If the pattern was found, this is an array of type `CArrayObject`
  * containing the substrings that matched the groups in the pattern, in the same order, if any.
  * @param  reference $foundString **OPTIONAL. OUTPUT.** If the pattern has been found after the method was called
  * with this parameter provided, the parameter's value, which is of type `CUStringObject`, is the first substring
  * that matched the pattern.
  *
  * @return bool `true` if the pattern was found in the string, `false` otherwise.
  */
 public function reFindGroups($findPattern, &$foundGroups, &$foundString = null)
 {
     $findPattern = self::ensureUModifier($findPattern);
     $ret = CRegex::findGroups($this, $findPattern, $foundGroups, $foundString);
     $foundGroups = to_oop($foundGroups);
     $foundString = to_oop($foundString);
     return $ret;
 }