Permalink
Browse files

Add function for test utf8 and add a description with accent in test

  • Loading branch information...
1 parent ac145cf commit 62afa323b2f1eb67b27fd11e5954873f74108b61 @stood stood committed Mar 6, 2014
@@ -266,13 +266,36 @@ public function getColumnFromRow($row, Table $table)
}
if ($desc){
- $column->setDescription(utf8_encode($desc));
+ if(!$this->isUtf8($desc))
+ $desc = utf8_encode($desc);
+ $column->setDescription($desc);
}
return $column;
}
/**
+ * Return True if $string is utf8
+ *
+ * @param string $string
+ *
+ * @return boolean
+ */
+ protected function isUtf8( $string)
+ {
+ return preg_match('%^(?:
+ [\x09\x0A\x0D\x20-\x7E] # ASCII
+ | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
+ | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
+ | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
+ | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
+ | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
+ | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
+ | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
+ )*$%xs', $string);
+ }
+
+ /**
* Load foreign keys for this table.
*/
protected function addForeignKeys(Table $table)
@@ -4,7 +4,7 @@ DROP VIEW IF EXISTS view_book_titles;
CREATE TABLE book
(
id INTEGER NOT NULL AUTO_INCREMENT COMMENT 'Book Id',
- title VARCHAR(255) NOT NULL COMMENT 'Book Title',
+ title VARCHAR(255) NOT NULL COMMENT 'Book Title with accent éài',
isbn VARCHAR(24) NOT NULL COMMENT 'ISBN Number',
price FLOAT COMMENT 'Price of the book.',
PRIMARY KEY (id)
@@ -92,7 +92,7 @@ public function testDecimal()
public function testDescColumn()
{
- $schema = '<database name="reverse_bookstore"><table name="book"><column name="title" type="VARCHAR" size="255" description="Book Title" /></table></database>';
+ $schema = '<database name="reverse_bookstore"><table name="book"><column name="title" type="VARCHAR" size="255" description="Book Title with accent éài" /></table></database>';
$xtad = new XmlToAppData();
$appData = $xtad->parseString($schema);
$database = $appData->getDatabase();

0 comments on commit 62afa32

Please sign in to comment.