Exemplo n.º 1
0
 protected function _initialize($addressBlock, $mode)
 {
     /* Set some safe default values. */
     $this->_company = '';
     $this->_firstName = '';
     $this->_middleName = '';
     $this->_lastName = '';
     $this->_addressLineOne = '';
     $this->_addressLineTwo = '';
     $this->_city = '';
     $this->_state = '';
     $this->_zip = '';
     $this->_email = '';
     $this->_phoneNumbers = array();
     /* Clear out any old data if this is not our first run this
      * instance.
      */
     $this->_addressBlock = array();
     /* Remove blank or space-only lines from address block. */
     $addressBlock = StringUtility::removeEmptyLines($addressBlock);
     /* Split address block into an array indexed by line number. */
     $addressBlockArray = explode("\n", $addressBlock);
     /* Trim whitespace/etc. from each line in the array. */
     $addressBlockArray = array_map(array($this, '_cleanAddressLine'), $addressBlockArray);
     $this->_addressBlock = $addressBlockArray;
     $this->_mode = $mode;
 }
Exemplo n.º 2
0
 function testRemoveEmptyLines()
 {
     $this->assertIdentical(StringUtility::removeEmptyLines("  \t\n\t\t\t\t\r\n\t\t\r\n\t\n                    "), '');
     $this->assertIdentical(StringUtility::removeEmptyLines("  \t\n\t\t\tWill Buckner\t\r\n\t\t\r\n\t\n                    "), 'Will Buckner');
     $this->assertIdentical(StringUtility::removeEmptyLines("\n\r\n\r\n\n"), '');
     $this->assertNotIdentical(StringUtility::removeEmptyLines("\n\ra\n\r\n\n"), '');
 }
 /**
  * Compresses a string of JavaScript code, removing whitespace, extra
  * newlines, and extra whitespace.
  *
  * @param string Uncompressed JavaScript source code.
  * @return string Compressed JavaScript code.
  */
 protected function compress($string)
 {
     /* Remove leading and trailing whitespace from each line (note, the
      * ungreedy modifier before the '$' in the below regular expression
      * should theoretically not be needed, but without it, it seems to
      * eat newlines.
      */
     $string = preg_replace('/^\\s*(.*?)\\s*?$/m', '\\1', $string);
     /* Remove C / C++ comments.
      *
      * \x27 is a single quote, \x5c is a backslash.
      *
      * This is based on code from Jeffrey Friedl's Mastering Regular
      * Expressions, 3rd Edition (O'Reilly Media, Inc.).
      *
      * If you're thinking about rewriting this, you'll probably break it.
      * It's very fragile ;).
      */
     $string = preg_replace('@([^"\\x27/]+|"[^\\x5c"]*(?:\\x5c.[^\\x5c"]*)*"[^"\\x27/]*|\\x27[^\\x27\\x5c]*(?:\\x5c.[^\\x27\\x5c]*)*\\x27[^"\\x27/]*)|/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/|//[^\\n]*@', '\\1', $string);
     /* Remove any blank lines from the string. */
     $string = StringUtility::removeEmptyLines($string);
     /* "Safe" newline removal. This should work with just about any code
      * that a browser's JavaScript implementation can understand.
      * Significant newlines will never be removed.
      */
     $string = preg_replace('/;\\n/', ';', $string);
     $string = preg_replace('/\\{\\n/', '{', $string);
     $string = preg_replace('/\\)\\n{/', ') {', $string);
     $string = preg_replace('/\\}\\nelse/', '} else', $string);
     $string = preg_replace('/else\\n\\{/', 'else {', $string);
     return $string;
 }