fixed problem with non utf8 chars
Esse commit está contido em:
@@ -78,6 +78,39 @@ class Lexer
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the string encoding and return a valid name
|
||||
* to be used on databases or restricted names
|
||||
*
|
||||
* @param String $word
|
||||
* @return String
|
||||
*/
|
||||
public function fixWordChars($word)
|
||||
{
|
||||
$word= strtolower($word);
|
||||
$word= $this->str_split_utf8($word);
|
||||
$str= "";
|
||||
for($i=0, $j=sizeof($word); $i<$j; $i++)
|
||||
{
|
||||
//$str.= strtr(utf8_decode($word[$i]), utf8_decode("ã"), "a");
|
||||
$str.= $this->translateChars($word[$i]);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fixed char to the sent char
|
||||
* @param string $char
|
||||
* @return string
|
||||
*/
|
||||
public function translateChars($str)
|
||||
{
|
||||
$str= strtolower($str);
|
||||
$from = $this->replacements[0];
|
||||
$to = $this->replacements[1];
|
||||
return strtr(utf8_decode($str), utf8_decode($from), $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a sweep over the sent content and replace any
|
||||
* special char, also removing any invalid char.
|
||||
@@ -125,6 +158,7 @@ class Lexer
|
||||
$letter= $this->tmpPeriod;
|
||||
}
|
||||
|
||||
//$fixed.= $this->translateChars($letter);
|
||||
$fixed.= $letter;
|
||||
}
|
||||
}
|
||||
@@ -157,17 +191,9 @@ class Lexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fixed char to the sent char
|
||||
* @param string $char
|
||||
* @return string
|
||||
* The constructor
|
||||
* @global Mind $_MIND
|
||||
*/
|
||||
public function translateChars($str)
|
||||
{
|
||||
$from = $this->replacements[0];
|
||||
$to = $this->replacements[1];
|
||||
return strtr($str, $from, $to);
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
|
||||
@@ -34,6 +34,23 @@ class Analyst {
|
||||
);
|
||||
}
|
||||
|
||||
public static function printWhatYouGet($detailed=false)
|
||||
{
|
||||
echo "Entities: ".sizeof(self::$entities)."\n";
|
||||
foreach(self::$entities as $entity)
|
||||
{
|
||||
echo " ".$entity->name."\n";
|
||||
}
|
||||
echo "Properties: "."\n";
|
||||
echo "Relations: "."\n";
|
||||
}
|
||||
|
||||
public static function reset()
|
||||
{
|
||||
self::$entities= Array();
|
||||
self::$relations= Array();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method receives each expression and analizes
|
||||
* the best way to act and to store the understood
|
||||
@@ -108,6 +125,9 @@ class Analyst {
|
||||
// if it is an entity
|
||||
if(MindEntity::isEntity($word))
|
||||
{
|
||||
// fixing any special char
|
||||
$word= Mind::$lexer->fixWordChars($word);
|
||||
|
||||
// yeah, I know it looks crazy, but try to follow my thoughts
|
||||
// let's instantiate a new Entity in case it has not been
|
||||
// instantiated before
|
||||
|
||||
@@ -62,6 +62,9 @@ class Syntaxer {
|
||||
// as we know it's only one block, we can use it straightly
|
||||
$matches= $matches[0];
|
||||
|
||||
// let's clear the Analyst memory as it uses static properties
|
||||
Analyst::reset();
|
||||
|
||||
// now we gotta analyse each valid expression
|
||||
foreach($matches as $found)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<special>áéíóúÁÉÍÓÚ"."ÀàÂâêÊîÎôÔûÛãÃõÕẽẼüÜçÇ</special>
|
||||
<numbers>1234567890</numbers>
|
||||
<symbols>\/!@#$%*()_-+=,.'":>&<</symbols>
|
||||
<!--<symbols>\/!@#$%&*()_-+=[]{},.'"</symbols>-->
|
||||
</validchars>
|
||||
<replacements>
|
||||
<from>áéíóúÁÉÍÓÚÀàÂâêÊîÎôÔûÛãÃõÕẽẼüÜçÇ</from>
|
||||
|
||||
@@ -63,6 +63,9 @@ EOT
|
||||
}
|
||||
|
||||
$startingTime= microtime();
|
||||
$startingTime= explode(' ', $startingTime);
|
||||
$startingTime= $startingTime[1] + $startingTime[0];
|
||||
|
||||
Mind::$lexer= new Lexer();
|
||||
|
||||
$srcs= Mind::$currentProject['sources'];
|
||||
@@ -89,9 +92,12 @@ EOT
|
||||
}
|
||||
|
||||
$endingTime= microtime();
|
||||
$endingTime= explode(' ', $endingTime);
|
||||
$endingTime= $endingTime[1] + $endingTime[0];
|
||||
|
||||
// do NOT print it if you have MANY entities, the webbrowser freezes
|
||||
//print_r(Analyst::getUniverse());
|
||||
echo Analyst::printWhatYouGet();
|
||||
echo "Time: ".
|
||||
number_format(((float)$endingTime) - ((float)$startingTime), 4).
|
||||
"s\n";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
aluno tem professor
|
||||
//professor tem piça
|
||||
|
||||
professor tem aluno
|
||||
aluno tem foto:arquivo(xx)
|
||||
/*
|
||||
@@ -12,5 +12,5 @@ blabelaebamimi
|
||||
aluno tem pai, mãe e papagaio.
|
||||
aluno tem nome:caractere(128, obrigatório, não nulo, "josé's da conceição")
|
||||
pai tem \pilha.
|
||||
mae tem nome, idade e sexo:char().
|
||||
mãe tem nome, idade e sexo.
|
||||
mae tem nome:varchar, idade:int e sexo:char().
|
||||
mãe tem nome:varchar, idade:int e sexo:char().
|
||||
Referência em uma Nova Issue
Bloquear um usuário