original_string: public static function xpathLiteral($s)
      {
          if (false === strpos($s, "'")) {
              return sprintf("'%s'", $s);
          }
  
          if (false === strpos($s, '"')) {
              return sprintf('"%s"', $s);
          }
  
          $string = $s;
          $parts = [];
          while (true) {
              if (false !== $pos = strpos($string, "'")) {
                  $parts[] = sprintf("'%s'", substr($string, 0, $pos));
                  $parts[] = "\"'\"";
                  $string = substr($string, $pos + 1);
              } else {
                  $parts[] = "'$string'";
                  break;
              }
          }
  
          return sprintf('concat(%s)', implode(', ', $parts));
      }
code: public static function xpathLiteral($s)
      {
          if (false === strpos($s, "'")) {
              return sprintf("'%s'", $s);
          }
  
          if (false === strpos($s, '"')) {
              return sprintf('"%s"', $s);
          }
  
          $string = $s;
          $parts = [];
          while (true) {
              if (false !== $pos = strpos($string, "'")) {
                  $parts[] = sprintf("'%s'", substr($string, 0, $pos));
                  $parts[] = "\"'\"";
                  $string = substr($string, $pos + 1);
              } else {
                  $parts[] = "'$string'";
                  break;
              }
          }
  
          return sprintf('concat(%s)', implode(', ', $parts));
      }
code_tokens: public static function xpathLiteral ( $ s ) { if ( false === strpos ( $ s , "'" ) ) { return sprintf ( "'%s'" , $ s ) ; } if ( false === strpos ( $ s , '"' ) ) { return sprintf ( '"%s"' , $ s ) ; } $ string = $ s ; $ parts = [ ] ; while ( true ) { if ( false !== $ pos = strpos ( $ string , "'" ) ) { $ parts [ ] = sprintf ( "'%s'" , substr ( $ string , 0 , $ pos ) ) ; $ parts [ ] = "\"'\"" ; $ string = substr ( $ string , $ pos + 1 ) ; } else { $ parts [ ] = "'$string'" ; break ; } } return sprintf ( 'concat(%s)' , implode ( ', ' , $ parts ) ) ; }
docstring: Converts string for XPath expressions.
  
  Escaped characters are: quotes (") and apostrophe (').
  
  Examples:
  
  echo Crawler::xpathLiteral('foo " bar');
  //prints 'foo " bar'
  
  echo Crawler::xpathLiteral("foo ' bar");
  //prints "foo ' bar"
  
  echo Crawler::xpathLiteral('a\'b"c');
  //prints concat('a', "'", 'b"c')
  
  
  @param string $s String to be escaped
  
  @return string Converted string
docstring_tokens: Converts string for XPath expressions .