oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00013     private static $_instance = null;
00014 
00020     public function __construct()
00021     {
00022     }
00023 
00029     public static function getInstance()
00030     {
00031         // disable caching for test modules
00032         if ( defined( 'OXID_PHP_UNIT' ) ) {
00033             static $inst = array();
00034             self::$_instance = $inst[oxClassCacheKey()];
00035         }
00036 
00037         if ( !self::$_instance instanceof oxUtilsString ) {
00038 
00039 
00040             self::$_instance = oxNew( 'oxUtilsString' );
00041 
00042             if ( defined( 'OXID_PHP_UNIT' ) ) {
00043                 $inst[oxClassCacheKey()] = self::$_instance;
00044             }
00045         }
00046         return self::$_instance;
00047     }
00048 
00049 
00057     public function prepareCSVField($sInField)
00058     {
00059         $oStr = getStr();
00060         if ($oStr->strstr($sInField, '"')) {
00061             return '"'.str_replace('"', '""', $sInField).'"';
00062         } elseif ($oStr->strstr($sInField, ';')) {
00063             return '"'.$sInField.'"';
00064         }
00065         return $sInField;
00066     }
00067 
00078     public function minimizeTruncateString( $sString, $iLength )
00079     {
00080         //leading and ending whitespaces
00081         $sString = trim( $sString );
00082 
00083         //multiple whitespaces
00084         $sString = preg_replace( "/[ \t\n\r]+/", " ", $sString );
00085         $oStr = getStr();
00086         if ( $oStr->strlen( $sString ) > $iLength && $iLength != -1 ) {
00087             $sString = $oStr->substr( $sString, 0, $iLength );
00088         }
00089 
00090         $sString = preg_replace( "/,+$/", "", $sString );
00091         return $sString;
00092     }
00093 
00101     public function prepareStrForSearch($sSearchStr)
00102     {
00103         $oStr = getStr();
00104         if ( $oStr->hasSpecialChars( $sSearchStr ) ) {
00105             return $oStr->recodeEntities( $sSearchStr, true, array( '&amp;' ), array( '&' ) );
00106         }
00107 
00108         return '';
00109     }
00110 }

Generated on Tue Aug 18 09:21:06 2009 for OXID eShop CE by  doxygen 1.5.5