CorujaStringManipulation Class Reference

List of all members.

Static Public Member Functions

static strToBool ($strText)
static forceInt ($strText)
static camelCaseToUnderlineCase ($strText)
static retab ($strText, $intDeeper)


Detailed Description

Class for string manipulations
Author:
Thiago Henrique Ramos da Mata <thiago.henrique.mata@gmail.com>

Definition at line 11 of file CorujaStringManipulation.class.php.


Member Function Documentation

static camelCaseToUnderlineCase ( strText  )  [static]

Change string case standard

Parameters:
string $strFieldName Name in camel case
Returns:
string Name in underline separated case
Exceptions:
InvalidArgumentException If $strText is not string
Example:
 \1 
returns
 true 
.... CorujaStringManipulation::caseTabUnderlineTab("nameOfTheParameter") // returns "NAME_OF_THE_PARAMETER"
Assert:
("test") == "TEST"
Assert:
("somethingCool") == "SOMETHING_COOL"
Assert:
("") == ""
Assert:
("1something2Cool3") == "1SOMETHING2_COOL3"
Assert:
("111something2222Cool333") == "111SOMETHING2222_COOL333"
Assert:
(null) throws InvalidArgumentException
Assert:
(123) throws InvalidArgumentException
Assert:
(array()) throws InvalidArgumentException
Assert:
(new stdClass()) throws InvalidArgumentException
Assert:
(false) throws InvalidArgumentException

Definition at line 125 of file CorujaStringManipulation.class.php.

Referenced by CorujaStringManipulationTest::testCamelCaseToUnderlineCase(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase10(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase2(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase3(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase4(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase5(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase6(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase7(), CorujaStringManipulationTest::testCamelCaseToUnderlineCase8(), and CorujaStringManipulationTest::testCamelCaseToUnderlineCase9().

00126         {
00127                 if(!is_string($strText))
00128                 {
00129                         throw new InvalidArgumentException("Invalid argument [ ". var_export($strText) ." ]. It should be string");
00130                 }
00131 
00132                 $arrFind = Array( "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" ,
00133                                           "P" , "Q" , "R" , "S" , "T" , "U" , "V" , "X" , "Z" , "W" , "Y"       );
00134 
00135                 $arrReplace = Array( "_A" , "_B" , "_C" , "_D" , "_E" , "_F" , "_G" , "_H" , "_I" , "_J" , "_K" , "_L" , "_M" ,
00136                                           "_N" , "_O" , "_P" , "_Q" , "_R" , "_S" , "_T" , "_U" , "_V" , "_X" , "_Z" , "_W" , "_Y"      );
00137 
00138                 if( strlen( $strText ) > 0 )
00139                 {
00140                         $strText[0] = strtolower($strText[0]);
00141                 }
00142 
00143                 return strtoupper( str_replace( $arrFind , $arrReplace , $strText ) );
00144         }

static forceInt ( strText  )  [static]

Get number chars inside a string

Parameters:
string $strText Text with numbers
Returns:
int Numbers in the string
Exceptions:
InvalidArgumentException If $strText is not string
Example:
 \1 
returns
 true 
.... forceInt("a1b2c3d4") // returns 1234
Assert:
("a1b2c3d4") == 1234
Assert:
("") == 0
Assert:
("a0a") == 0
Assert:
("001") == 1
Assert:
("abc") == 0
Assert:
("a-10") == 10
Assert:
("-10") == -10
Assert:
("--10") == -10
Assert:
("-a-b-1-0-") == -10
Assert:
(null) throws InvalidArgumentException
Assert:
(123) throws InvalidArgumentException
Assert:
(array()) throws InvalidArgumentException
Assert:
(new stdClass()) throws InvalidArgumentException
Assert:
(false) throws InvalidArgumentException

Definition at line 79 of file CorujaStringManipulation.class.php.

Referenced by CorujaStringManipulationTest::testForceInt(), CorujaStringManipulationTest::testForceInt10(), CorujaStringManipulationTest::testForceInt11(), CorujaStringManipulationTest::testForceInt12(), CorujaStringManipulationTest::testForceInt13(), CorujaStringManipulationTest::testForceInt14(), CorujaStringManipulationTest::testForceInt2(), CorujaStringManipulationTest::testForceInt3(), CorujaStringManipulationTest::testForceInt4(), CorujaStringManipulationTest::testForceInt5(), CorujaStringManipulationTest::testForceInt6(), CorujaStringManipulationTest::testForceInt7(), CorujaStringManipulationTest::testForceInt8(), and CorujaStringManipulationTest::testForceInt9().

00080         {
00081                 if(!is_string($strText))
00082                 {
00083                         throw new InvalidArgumentException("Invalid argument [ ". var_export($strText) ." ]. It should be string");
00084                 }
00085 
00086                 $arrNum = Array( "0","1","2","3","4","5","6","7","8","9");
00087                 $strResult = "";
00088                 for( $i = 0; $i < strlen( $strText ); ++$i )
00089                 {
00090                         $charLetra = $strText[$i];
00091                         if( $i == 0 && $charLetra == "-" )
00092                         {
00093                                 $strResult .= $charLetra;
00094                         }
00095                         if( in_array($charLetra,$arrNum))
00096                         {
00097                                 $strResult .= $charLetra;
00098                         }
00099                 }
00100                 return $strResult += 0;
00101         }

static retab ( strText,
intDeeper 
) [static]

Definition at line 146 of file CorujaStringManipulation.class.php.

Referenced by CodeReflectionFunction::createFunctionHeaderCode(), CodeReflectionMethod::createMethodHeaderCode(), CodeInstrumentationMethod::createMethodHeaderCode(), CodeInstrumentationMethod::getCallCodeInstrFunctionHeaderCode(), and CodeReflectionProperty::getCode().

00147         {
00148                 $arrText = explode( "\n" , $strText );
00149                 foreach( $arrText as $intKey => $strTextElement)
00150                 {
00151                         $arrText [ $intKey ] = trim( $strTextElement );
00152                 }
00153                 $strTab = "\n" .str_repeat( "\t" , $intDeeper );
00154                 $strText = $strTab . implode( $strTab , $arrText ) . $strTab;
00155                 return $strText;
00156         }

static strToBool ( strText  )  [static]

Special string casting for boolean

Parameters:
string $strText String to be turned into boolean
Returns:
boolean Input casting
Exceptions:
InvalidArgumentException If $strText is not string
Example:
 \1 
returns
 true 
.... strToBool("false") // returns false
Assert:
("") == false
Assert:
("false") == false
Assert:
("FaLsE") == false
Assert:
("0") == false
Assert:
("a0a") == true
Assert:
("true") == true
Assert:
("1") == true
Assert:
(null) throws InvalidArgumentException
Assert:
(123) throws InvalidArgumentException
Assert:
(array()) throws InvalidArgumentException
Assert:
(new stdClass()) throws InvalidArgumentException
Assert:
(false) throws InvalidArgumentException

Definition at line 38 of file CorujaStringManipulation.class.php.

Referenced by CorujaStringManipulationTest::testStrToBool(), CorujaStringManipulationTest::testStrToBool10(), CorujaStringManipulationTest::testStrToBool11(), CorujaStringManipulationTest::testStrToBool12(), CorujaStringManipulationTest::testStrToBool2(), CorujaStringManipulationTest::testStrToBool3(), CorujaStringManipulationTest::testStrToBool4(), CorujaStringManipulationTest::testStrToBool5(), CorujaStringManipulationTest::testStrToBool6(), CorujaStringManipulationTest::testStrToBool7(), CorujaStringManipulationTest::testStrToBool8(), and CorujaStringManipulationTest::testStrToBool9().

00039         {
00040                 if(!is_string($strText))
00041                 {
00042                         throw new InvalidArgumentException("Invalid argument [ ". var_export($strText) ." ]. It should be string");
00043                 }
00044 
00045                 $strText = strtolower( $strText );
00046                 if ( $strText === "false" || $strText === "" || $strText === "0" )
00047                 {
00048                         return( false );
00049                 }
00050                 return( true );
00051         }


The documentation for this class was generated from the following file:

Generated on Thu Feb 3 03:55:03 2011 for CodeToDiagram by  doxygen 1.5.9