예제 #1
0
 /**
  * @return array
  */
 public function asConfig()
 {
     if (!count($this->collection)) {
         return;
     }
     // Grab the emoticons from the collection
     $codes = array_keys(iterator_to_array($this->collection));
     // Build the regexp used to match emoticons
     $regexp = '/';
     if ($this->notAfter !== '') {
         $regexp .= '(?<!' . $this->notAfter . ')';
     }
     $regexp .= RegexpBuilder::fromList($codes);
     if ($this->notBefore !== '') {
         $regexp .= '(?!' . $this->notBefore . ')';
     }
     $regexp .= '/S';
     // Set the Unicode mode if Unicode properties are used
     if (preg_match('/\\\\[pP](?>\\{\\^?\\w+\\}|\\w\\w?)/', $regexp)) {
         $regexp .= 'u';
     }
     // Force the regexp to use atomic grouping for performance
     $regexp = preg_replace('/(?<!\\\\)((?>\\\\\\\\)*)\\(\\?:/', '$1(?>', $regexp);
     // Prepare the config array
     $config = ['quickMatch' => $this->quickMatch, 'regexp' => $regexp, 'tagName' => $this->tagName];
     // If notAfter is used, we need to create a JavaScript-specific regexp that does not use a
     // lookbehind assertion, and we add the notAfter subpattern to the config as a variant
     if ($this->notAfter !== '') {
         // Skip the first assertion by skipping the first N characters, where N equals the
         // length of $this->notAfter plus 1 for the first "/" and 5 for "(?<!)"
         $lpos = 6 + strlen($this->notAfter);
         $rpos = strrpos($regexp, '/');
         $jsRegexp = RegexpConvertor::toJS('/' . substr($regexp, $lpos, $rpos - $lpos) . '/', true);
         $config['regexp'] = new Variant($regexp);
         $config['regexp']->set('JS', $jsRegexp);
         $config['notAfter'] = new Variant();
         $config['notAfter']->set('JS', RegexpConvertor::toJS('/' . $this->notAfter . '/'));
     }
     // Try to find a quickMatch if none is set
     if ($this->quickMatch === false) {
         $config['quickMatch'] = ConfigHelper::generateQuickMatchFromList($codes);
     }
     return $config;
 }
예제 #2
0
 public function asConfig()
 {
     if (!\count($this->collection)) {
         return;
     }
     $codes = \array_keys(\iterator_to_array($this->collection));
     $regexp = '/';
     if ($this->notAfter !== '') {
         $regexp .= '(?<!' . $this->notAfter . ')';
     }
     $regexp .= RegexpBuilder::fromList($codes);
     if ($this->notBefore !== '') {
         $regexp .= '(?!' . $this->notBefore . ')';
     }
     $regexp .= '/S';
     if (\preg_match('/\\\\[pP](?>\\{\\^?\\w+\\}|\\w\\w?)/', $regexp)) {
         $regexp .= 'u';
     }
     $regexp = \preg_replace('/(?<!\\\\)((?>\\\\\\\\)*)\\(\\?:/', '$1(?>', $regexp);
     $config = array('quickMatch' => $this->quickMatch, 'regexp' => $regexp, 'tagName' => $this->tagName);
     if ($this->notAfter !== '') {
         $lpos = 6 + \strlen($this->notAfter);
         $rpos = \strrpos($regexp, '/');
         $jsRegexp = RegexpConvertor::toJS('/' . \substr($regexp, $lpos, $rpos - $lpos) . '/', \true);
         $config['regexp'] = new Variant($regexp);
         $config['regexp']->set('JS', $jsRegexp);
         $config['notAfter'] = new Variant();
         $config['notAfter']->set('JS', RegexpConvertor::toJS('/' . $this->notAfter . '/'));
     }
     if ($this->quickMatch === \false) {
         $config['quickMatch'] = ConfigHelper::generateQuickMatchFromList($codes);
     }
     return $config;
 }
예제 #3
0
 public function asConfig()
 {
     $config = array('attrName' => $this->attrName, 'tagName' => $this->tagName);
     if (!empty($this->aliases)) {
         $aliases = \array_keys($this->aliases);
         $regexp = '/' . RegexpBuilder::fromList($aliases) . '/';
         $config['aliases'] = $this->aliases;
         $config['aliasesRegexp'] = new Regexp($regexp, \true);
         $quickMatch = ConfigHelper::generateQuickMatchFromList($aliases);
         if ($quickMatch !== \false) {
             $config['aliasesQuickMatch'] = $quickMatch;
         }
     }
     return $config;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getJSHints()
 {
     $quickMatch = ConfigHelper::generateQuickMatchFromList(array_keys($this->aliases));
     return ['EMOJI_HAS_ALIASES' => !empty($this->aliases), 'EMOJI_HAS_ALIAS_QUICKMATCH' => $quickMatch !== false];
 }