Index: t3lib/class.t3lib_cs.php
===================================================================
--- t3lib/class.t3lib_cs.php	(revision 9283)
+++ t3lib/class.t3lib_cs.php	(revision )
@@ -1,26 +1,26 @@
 <?php
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 2003-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+ *  Copyright notice
+ *
+ *  (c) 2003-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  All rights reserved
+ *
+ *  This script is part of the Typo3 project. The Typo3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
 /**
  * Class for conversion between charsets.
  *
@@ -35,53 +35,53 @@
  *
  *
  *  136: class t3lib_cs
- *  488:     function parse_charset($charset)
+ *  488:	 function parse_charset($charset)
- *  507:     function get_locale_charset($locale)
+ *  507:	 function get_locale_charset($locale)
  *
- *              SECTION: Charset Conversion functions
+ *			  SECTION: Charset Conversion functions
- *  560:     function conv($str,$fromCS,$toCS,$useEntityForNoChar=0)
+ *  560:	 function conv($str,$fromCS,$toCS,$useEntityForNoChar=0)
- *  600:     function convArray(&$array,$fromCS,$toCS,$useEntityForNoChar=0)
+ *  600:	 function convArray(&$array,$fromCS,$toCS,$useEntityForNoChar=0)
- *  617:     function utf8_encode($str,$charset)
+ *  617:	 function utf8_encode($str,$charset)
- *  663:     function utf8_decode($str,$charset,$useEntityForNoChar=0)
+ *  663:	 function utf8_decode($str,$charset,$useEntityForNoChar=0)
- *  706:     function utf8_to_entities($str)
+ *  706:	 function utf8_to_entities($str)
- *  739:     function entities_to_utf8($str,$alsoStdHtmlEnt=0)
+ *  739:	 function entities_to_utf8($str,$alsoStdHtmlEnt=0)
- *  773:     function utf8_to_numberarray($str,$convEntities=0,$retChar=0)
+ *  773:	 function utf8_to_numberarray($str,$convEntities=0,$retChar=0)
- *  823:     function UnumberToChar($cbyte)
+ *  823:	 function UnumberToChar($cbyte)
- *  868:     function utf8CharToUnumber($str,$hex=0)
+ *  868:	 function utf8CharToUnumber($str,$hex=0)
  *
- *              SECTION: Init functions
+ *			  SECTION: Init functions
- *  911:     function initCharset($charset)
+ *  911:	 function initCharset($charset)
- *  973:     function initUnicodeData($mode=null)
+ *  973:	 function initUnicodeData($mode=null)
- * 1198:     function initCaseFolding($charset)
+ * 1198:	 function initCaseFolding($charset)
- * 1260:     function initToASCII($charset)
+ * 1260:	 function initToASCII($charset)
  *
- *              SECTION: String operation functions
+ *			  SECTION: String operation functions
- * 1331:     function substr($charset,$string,$start,$len=null)
+ * 1331:	 function substr($charset,$string,$start,$len=null)
- * 1384:     function strlen($charset,$string)
+ * 1384:	 function strlen($charset,$string)
- * 1414:     function crop($charset,$string,$len,$crop='')
+ * 1414:	 function crop($charset,$string,$len,$crop='')
- * 1467:     function strtrunc($charset,$string,$len)
+ * 1467:	 function strtrunc($charset,$string,$len)
- * 1501:     function conv_case($charset,$string,$case)
+ * 1501:	 function conv_case($charset,$string,$case)
- * 1527:     function specCharsToASCII($charset,$string)
+ * 1527:	 function specCharsToASCII($charset,$string)
  *
- *              SECTION: Internal string operation functions
+ *			  SECTION: Internal string operation functions
- * 1567:     function sb_char_mapping($str,$charset,$mode,$opt='')
+ * 1567:	 function sb_char_mapping($str,$charset,$mode,$opt='')
  *
- *              SECTION: Internal UTF-8 string operation functions
+ *			  SECTION: Internal UTF-8 string operation functions
- * 1622:     function utf8_substr($str,$start,$len=null)
+ * 1622:	 function utf8_substr($str,$start,$len=null)
- * 1655:     function utf8_strlen($str)
+ * 1655:	 function utf8_strlen($str)
- * 1676:     function utf8_strtrunc($str,$len)
+ * 1676:	 function utf8_strtrunc($str,$len)
- * 1698:     function utf8_strpos($haystack,$needle,$offset=0)
+ * 1698:	 function utf8_strpos($haystack,$needle,$offset=0)
- * 1723:     function utf8_strrpos($haystack,$needle)
+ * 1723:	 function utf8_strrpos($haystack,$needle)
- * 1745:     function utf8_char2byte_pos($str,$pos)
+ * 1745:	 function utf8_char2byte_pos($str,$pos)
- * 1786:     function utf8_byte2char_pos($str,$pos)
+ * 1786:	 function utf8_byte2char_pos($str,$pos)
- * 1809:     function utf8_char_mapping($str,$mode,$opt='')
+ * 1809:	 function utf8_char_mapping($str,$mode,$opt='')
  *
- *              SECTION: Internal EUC string operation functions
+ *			  SECTION: Internal EUC string operation functions
- * 1885:     function euc_strtrunc($str,$len,$charset)
+ * 1885:	 function euc_strtrunc($str,$len,$charset)
- * 1914:     function euc_substr($str,$start,$charset,$len=null)
+ * 1914:	 function euc_substr($str,$start,$charset,$len=null)
- * 1939:     function euc_strlen($str,$charset)
+ * 1939:	 function euc_strlen($str,$charset)
- * 1966:     function euc_char2byte_pos($str,$pos,$charset)
+ * 1966:	 function euc_char2byte_pos($str,$pos,$charset)
- * 2007:     function euc_char_mapping($str,$charset,$mode,$opt='')
+ * 2007:	 function euc_char_mapping($str,$charset,$mode,$opt='')
  *
  * TOTAL FUNCTIONS: 35
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -89,12 +89,6 @@
  */
 
 
-
-
-
-
-
-
 /**
  * Notes on UTF-8
  *
@@ -133,41 +127,41 @@
  * @subpackage t3lib
  */
 class t3lib_cs {
-	var $noCharByteVal=63;		// ASCII Value for chars with no equivalent.
+	var $noCharByteVal = 63; // ASCII Value for chars with no equivalent.
 
 		// This is the array where parsed conversion tables are stored (cached)
-	var $parsedCharsets=array();
+	var $parsedCharsets = array();
 
 		// An array where case folding data will be stored (cached)
-	var $caseFolding=array();
+	var $caseFolding = array();
 
 		// An array where charset-to-ASCII mappings are stored (cached)
-	var $toASCII=array();
+	var $toASCII = array();
 
 		// This tells the converter which charsets has two bytes per char:
-	var $twoByteSets=array(
+	var $twoByteSets = array(
-		'ucs-2'=>1,	// 2-byte Unicode
+		'ucs-2' => 1, // 2-byte Unicode
 	);
 
 		// This tells the converter which charsets has four bytes per char:
-	var $fourByteSets=array(
+	var $fourByteSets = array(
-		'ucs-4'=>1,	// 4-byte Unicode
+		'ucs-4' => 1, // 4-byte Unicode
-		'utf-32'=>1,	// 4-byte Unicode (limited to the 21-bits of UTF-16)
+		'utf-32' => 1, // 4-byte Unicode (limited to the 21-bits of UTF-16)
 	);
 
 		// This tells the converter which charsets use a scheme like the Extended Unix Code:
-	var $eucBasedSets=array(
+	var $eucBasedSets = array(
-		'gb2312'=>1,		// Chinese, simplified.
+		'gb2312' => 1, // Chinese, simplified.
-		'big5'=>1,		// Chinese, traditional.
+		'big5' => 1, // Chinese, traditional.
-		'euc-kr'=>1,		// Korean
+		'euc-kr' => 1, // Korean
-		'shift_jis'=>1,		// Japanese - WARNING: Shift-JIS includes half-width katakana single-bytes characters above 0x80!
+		'shift_jis' => 1, // Japanese - WARNING: Shift-JIS includes half-width katakana single-bytes characters above 0x80!
 	);
 
 		// see	http://developer.apple.com/documentation/macos8/TextIntlSvcs/TextEncodingConversionManager/TEC1.5/TEC.b0.html
 		// http://czyborra.com/charsets/iso8859.html
-	var $synonyms=array(
+	var $synonyms = array(
 		'us' => 'ascii',
-		'us-ascii'=> 'ascii',
+		'us-ascii' => 'ascii',
 		'cp819' => 'iso-8859-1',
 		'ibm819' => 'iso-8859-1',
 		'iso-ir-100' => 'iso-8859-1',
@@ -252,116 +246,116 @@
 	);
 
 		// mapping of iso-639-1 language codes to script names
-	var $lang_to_script=array(
+	var $lang_to_script = array(
 			// iso-639-1 language codes, see http://www.loc.gov/standards/iso639-2/php/code_list.php
 		'ar' => 'arabic',
-		'bg' => 'cyrillic',		// Bulgarian
+		'bg' => 'cyrillic', // Bulgarian
-		'bs' => 'east_european',	// Bosnian
+		'bs' => 'east_european', // Bosnian
-		'cs' => 'east_european',	// Czech
+		'cs' => 'east_european', // Czech
-		'da' => 'west_european',	// Danish
+		'da' => 'west_european', // Danish
-		'de' => 'west_european',	// German
+		'de' => 'west_european', // German
-		'es' => 'west_european',	// Spanish
+		'es' => 'west_european', // Spanish
 		'et' => 'estonian',
-		'eo' => 'unicode',		// Esperanto
+		'eo' => 'unicode', // Esperanto
-		'eu' => 'west_european',	// Basque
+		'eu' => 'west_european', // Basque
-		'fa' => 'arabic',	// Persian
+		'fa' => 'arabic', // Persian
-		'fi' => 'west_european',	// Finish
+		'fi' => 'west_european', // Finish
-		'fo' => 'west_european',	// Faroese
+		'fo' => 'west_european', // Faroese
-		'fr' => 'west_european',	// French
+		'fr' => 'west_european', // French
-		'ga' => 'west_european',	// Galician
+		'ga' => 'west_european', // Galician
-		'ge' => 'unicode',			// Georgian
+		'ge' => 'unicode', // Georgian
 		'gr' => 'greek',
-		'he' => 'hebrew',		// Hebrew (since 1998)
+		'he' => 'hebrew', // Hebrew (since 1998)
-		'hi' => 'unicode',		// Hindi
+		'hi' => 'unicode', // Hindi
-		'hr' => 'east_european',	// Croatian
+		'hr' => 'east_european', // Croatian
-		'hu' => 'east_european',	// Hungarian
+		'hu' => 'east_european', // Hungarian
-		'iw' => 'hebrew',		// Hebrew (til 1998)
+		'iw' => 'hebrew', // Hebrew (til 1998)
-		'is' => 'west_european',	// Icelandic
+		'is' => 'west_european', // Icelandic
-		'it' => 'west_european',	// Italian
+		'it' => 'west_european', // Italian
 		'ja' => 'japanese',
-		'kl' => 'west_european',	// Greenlandic
+		'kl' => 'west_european', // Greenlandic
-		'km' => 'unicode',	// Khmer
+		'km' => 'unicode', // Khmer
 		'ko' => 'korean',
 		'lt' => 'lithuanian',
-		'lv' => 'west_european',	// Latvian/Lettish
+		'lv' => 'west_european', // Latvian/Lettish
-		'nl' => 'west_european',	// Dutch
+		'nl' => 'west_european', // Dutch
-		'no' => 'west_european',	// Norwegian
+		'no' => 'west_european', // Norwegian
-		'nb' => 'west_european',	// Norwegian Bokmal
+		'nb' => 'west_european', // Norwegian Bokmal
-		'nn' => 'west_european',	// Norwegian Nynorsk
+		'nn' => 'west_european', // Norwegian Nynorsk
-		'pl' => 'east_european',	// Polish
+		'pl' => 'east_european', // Polish
-		'pt' => 'west_european',	// Portuguese
+		'pt' => 'west_european', // Portuguese
-		'ro' => 'east_european',	// Romanian
+		'ro' => 'east_european', // Romanian
-		'ru' => 'cyrillic',		// Russian
+		'ru' => 'cyrillic', // Russian
-		'sk' => 'east_european',	// Slovak
+		'sk' => 'east_european', // Slovak
-		'sl' => 'east_european',	// Slovenian
+		'sl' => 'east_european', // Slovenian
-		'sr' => 'cyrillic',		// Serbian
+		'sr' => 'cyrillic', // Serbian
-		'sv' => 'west_european',	// Swedish
+		'sv' => 'west_european', // Swedish
-		'sq' => 'albanian',		// Albanian
+		'sq' => 'albanian', // Albanian
 		'th' => 'thai',
-		'uk' => 'cyrillic',		// Ukranian
+		'uk' => 'cyrillic', // Ukranian
 		'vi' => 'vietnamese',
 		'zh' => 'chinese',
 			// MS language codes, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_language_strings.asp
 			// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceinternational5/html/wce50conLanguageIdentifiersandLocales.asp
 		'ara' => 'arabic',
-		'bgr' => 'cyrillic',		// Bulgarian
+		'bgr' => 'cyrillic', // Bulgarian
-		'cat' => 'west_european',	// Catalan
+		'cat' => 'west_european', // Catalan
 		'chs' => 'simpl_chinese',
 		'cht' => 'trad_chinese',
-		'csy' => 'east_european',	// Czech
+		'csy' => 'east_european', // Czech
-		'dan' => 'west_european',	// Danisch
+		'dan' => 'west_european', // Danisch
-		'deu' => 'west_european',	// German
+		'deu' => 'west_european', // German
-		'dea' => 'west_european',	// German (Austrian)
+		'dea' => 'west_european', // German (Austrian)
-		'des' => 'west_european',	// German (Swiss)
+		'des' => 'west_european', // German (Swiss)
-		'ena' => 'west_european',	// English (Australian)
+		'ena' => 'west_european', // English (Australian)
-		'enc' => 'west_european',	// English (Canadian)
+		'enc' => 'west_european', // English (Canadian)
-		'eng' => 'west_european',	// English
+		'eng' => 'west_european', // English
-		'enz' => 'west_european',	// English (New Zealand)
+		'enz' => 'west_european', // English (New Zealand)
-		'enu' => 'west_european',	// English (United States)
+		'enu' => 'west_european', // English (United States)
-		'euq' => 'west_european',	// Basque
+		'euq' => 'west_european', // Basque
-		'fos' => 'west_european',	// Faroese
+		'fos' => 'west_european', // Faroese
-		'far' => 'arabic',	// Persian
+		'far' => 'arabic', // Persian
-		'fin' => 'west_european',	// Finish
+		'fin' => 'west_european', // Finish
-		'fra' => 'west_european',	// French
+		'fra' => 'west_european', // French
-		'frb' => 'west_european',	// French (Belgian)
+		'frb' => 'west_european', // French (Belgian)
-		'frc' => 'west_european',	// French (Canadian)
+		'frc' => 'west_european', // French (Canadian)
-		'frs' => 'west_european',	// French (Swiss)
+		'frs' => 'west_european', // French (Swiss)
-		'geo' => 'unicode',			// Georgian
+		'geo' => 'unicode', // Georgian
-		'glg' => 'west_european',	// Galician
+		'glg' => 'west_european', // Galician
 		'ell' => 'greek',
 		'heb' => 'hebrew',
-		'hin' => 'unicode',	// Hindi
+		'hin' => 'unicode', // Hindi
-		'hun' => 'east_european',	// Hungarian
+		'hun' => 'east_european', // Hungarian
-		'isl' => 'west_euorpean',	// Icelandic
+		'isl' => 'west_euorpean', // Icelandic
-		'ita' => 'west_european',	// Italian
+		'ita' => 'west_european', // Italian
-		'its' => 'west_european',	// Italian (Swiss)
+		'its' => 'west_european', // Italian (Swiss)
 		'jpn' => 'japanese',
-		'khm' => 'unicode',	// Khmer
+		'khm' => 'unicode', // Khmer
 		'kor' => 'korean',
 		'lth' => 'lithuanian',
-		'lvi' => 'west_european',	// Latvian/Lettish
+		'lvi' => 'west_european', // Latvian/Lettish
-		'msl' => 'west_european',	// Malay
+		'msl' => 'west_european', // Malay
-		'nlb' => 'west_european',	// Dutch (Belgian)
+		'nlb' => 'west_european', // Dutch (Belgian)
-		'nld' => 'west_european',	// Dutch
+		'nld' => 'west_european', // Dutch
-		'nor' => 'west_european',	// Norwegian (bokmal)
+		'nor' => 'west_european', // Norwegian (bokmal)
-		'non' => 'west_european',	// Norwegian (nynorsk)
+		'non' => 'west_european', // Norwegian (nynorsk)
-		'plk' => 'east_european',	// Polish
+		'plk' => 'east_european', // Polish
-		'ptg' => 'west_european',	// Portuguese
+		'ptg' => 'west_european', // Portuguese
-		'ptb' => 'west_european',	// Portuguese (Brazil)
+		'ptb' => 'west_european', // Portuguese (Brazil)
-		'rom' => 'east_european',	// Romanian
+		'rom' => 'east_european', // Romanian
-		'rus' => 'cyrillic',		// Russian
+		'rus' => 'cyrillic', // Russian
-		'slv' => 'east_european',	// Slovenian
+		'slv' => 'east_european', // Slovenian
-		'sky' => 'east_european',	// Slovak
+		'sky' => 'east_european', // Slovak
-		'srl' => 'east_european',	// Serbian (Latin)
+		'srl' => 'east_european', // Serbian (Latin)
-		'srb' => 'cyrillic',		// Serbian (Cyrillic)
+		'srb' => 'cyrillic', // Serbian (Cyrillic)
-		'esp' => 'west_european',	// Spanish (trad. sort)
+		'esp' => 'west_european', // Spanish (trad. sort)
-		'esm' => 'west_european',	// Spanish (Mexican)
+		'esm' => 'west_european', // Spanish (Mexican)
-		'esn' => 'west_european',	// Spanish (internat. sort)
+		'esn' => 'west_european', // Spanish (internat. sort)
-		'sve' => 'west_european',	// Swedish
+		'sve' => 'west_european', // Swedish
-		'sqi' => 'albanian',		// Albanian
+		'sqi' => 'albanian', // Albanian
 		'tha' => 'thai',
 		'trk' => 'turkish',
-		'ukr' => 'cyrillic',	// Ukrainian
+		'ukr' => 'cyrillic', // Ukrainian
 			// English language names
 		'albanian' => 'albanian',
 		'arabic' => 'arabic',
@@ -412,7 +406,7 @@
 	);
 
 		// mapping of language (family) names to charsets on Unix
-	var $script_to_charset_unix=array(
+	var $script_to_charset_unix = array(
 		'west_european' => 'iso-8859-1',
 		'estonian' => 'iso-8859-1',
 		'east_european' => 'iso-8859-2',
@@ -435,7 +429,7 @@
 	);
 
 		// mapping of language (family) names to charsets on Windows
-	var $script_to_charset_windows=array(
+	var $script_to_charset_windows = array(
 		'east_european' => 'windows-1250',
 		'cyrillic' => 'windows-1251',
 		'west_european' => 'windows-1252',
@@ -458,7 +452,7 @@
 	);
 
 		// mapping of locale names to charsets
-	var $locale_to_charset=array(
+	var $locale_to_charset = array(
 		'japanese.euc' => 'euc-jp',
 		'ja_jp.ujis' => 'euc-jp',
 		'korean.euc' => 'euc-kr',
@@ -548,9 +542,11 @@
 	 * @return	string		Normalized charset
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function parse_charset($charset)	{
+	function parse_charset($charset) {
 		$charset = trim(strtolower($charset));
-		if (isset($this->synonyms[$charset]))	$charset = $this->synonyms[$charset];
+		if (isset($this->synonyms[$charset])) {
+			$charset = $this->synonyms[$charset];
+		}
 
 		return $charset;
 	}
@@ -558,36 +554,44 @@
 	/**
 	 * Get the charset of a locale.
 	 *
-	 * ln            language
+	 * ln			language
-	 * ln_CN         language / country
+	 * ln_CN		 language / country
-	 * ln_CN.cs      language / country / charset
+	 * ln_CN.cs	  language / country / charset
 	 * ln_CN.cs@mod  language / country / charset / modifier
 	 *
 	 * @param	string		Locale string
 	 * @return	string		Charset resolved for locale string
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function get_locale_charset($locale)	{
+	function get_locale_charset($locale) {
 		$locale = strtolower($locale);
 
 			// exact locale specific charset?
-		if (isset($this->locale_to_charset[$locale]))	return $this->locale_to_charset[$locale];
+		if (isset($this->locale_to_charset[$locale])) {
+			return $this->locale_to_charset[$locale];
+		}
 
 			// get modifier
-		list($locale,$modifier) = explode('@',$locale);
+		list($locale, $modifier) = explode('@', $locale);
 
 			// locale contains charset: use it
-		list($locale,$charset) = explode('.',$locale);
+		list($locale, $charset) = explode('.', $locale);
-		if ($charset)	return $this->parse_charset($charset);
+		if ($charset) {
+			return $this->parse_charset($charset);
+		}
 
 			// modifier is 'euro' (after charset check, because of xx.utf-8@euro)
-		if ($modifier == 'euro')	return 'iso-8859-15';
+		if ($modifier == 'euro') {
+			return 'iso-8859-15';
+		}
 
 			// get language
-		list($language,$country) = explode('_',$locale);
+		list($language, $country) = explode('_', $locale);
-		if (isset($this->lang_to_script[$language]))	$script = $this->lang_to_script[$language];
+		if (isset($this->lang_to_script[$language])) {
+			$script = $this->lang_to_script[$language];
+		}
 
-		if (TYPO3_OS == 'WIN')	{
+		if (TYPO3_OS == 'WIN') {
 			$cs = $this->script_to_charset_windows[$script] ? $this->script_to_charset_windows[$script] : 'windows-1252';
 		} else {
 			$cs = $this->script_to_charset_unix[$script] ? $this->script_to_charset_unix[$script] : 'iso-8859-1';
@@ -597,13 +601,6 @@
 	}
 
 
-
-
-
-
-
-
-
 	/********************************************
 	 *
 	 * Charset Conversion functions
@@ -620,32 +617,44 @@
 	 * @return	string		Converted string
 	 * @see convArray()
 	 */
-	function conv($str,$fromCS,$toCS,$useEntityForNoChar=0)	{
+	function conv($str, $fromCS, $toCS, $useEntityForNoChar = 0) {
-		if ($fromCS==$toCS)	return $str;
+		if ($fromCS == $toCS) {
+			return $str;
+		}
 
 			// PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything
-		if ($toCS=='utf-8' || !$useEntityForNoChar)	{
+		if ($toCS == 'utf-8' || !$useEntityForNoChar) {
-			switch($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'])	{
+			switch ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod']) {
-			case 'mbstring':
+				case 'mbstring':
-				$conv_str = mb_convert_encoding($str,$toCS,$fromCS);
+					$conv_str = mb_convert_encoding($str, $toCS, $fromCS);
-				if (false !== $conv_str)	return $conv_str; // returns false for unsupported charsets
+					if (FALSE !== $conv_str) {
+						return $conv_str;
+					} // returns false for unsupported charsets
-				break;
+					break;
 
-			case 'iconv':
+				case 'iconv':
-				$conv_str = iconv($fromCS,$toCS.'//TRANSLIT',$str);
+					$conv_str = iconv($fromCS, $toCS . '//TRANSLIT', $str);
-				if (false !== $conv_str)	return $conv_str;
+					if (FALSE !== $conv_str) {
+						return $conv_str;
+					}
-				break;
+					break;
 
-			case 'recode':
+				case 'recode':
-				$conv_str = recode_string($fromCS.'..'.$toCS,$str);
+					$conv_str = recode_string($fromCS . '..' . $toCS, $str);
-				if (false !== $conv_str)	return $conv_str;
+					if (FALSE !== $conv_str) {
+						return $conv_str;
+					}
-				break;
+					break;
 			}
 			// fallback to TYPO3 conversion
 		}
 
-		if ($fromCS!='utf-8')	$str=$this->utf8_encode($str,$fromCS);
-		if ($toCS!='utf-8')	$str=$this->utf8_decode($str,$toCS,$useEntityForNoChar);
+		if ($fromCS != 'utf-8') {
+			$str = $this->utf8_encode($str, $fromCS);
+		}
+		if ($toCS != 'utf-8') {
+			$str = $this->utf8_decode($str, $toCS, $useEntityForNoChar);
+		}
 		return $str;
 	}
 
@@ -660,12 +669,12 @@
 	 * @return	void
 	 * @see conv()
 	 */
-	function convArray(&$array,$fromCS,$toCS,$useEntityForNoChar=0)	{
+	function convArray(&$array, $fromCS, $toCS, $useEntityForNoChar = 0) {
-		foreach($array as $key => $value)	{
+		foreach ($array as $key => $value) {
-			if (is_array($array[$key]))	{
+			if (is_array($array[$key])) {
-				$this->convArray($array[$key],$fromCS,$toCS,$useEntityForNoChar);
+				$this->convArray($array[$key], $fromCS, $toCS, $useEntityForNoChar);
 			} elseif (is_string($array[$key])) {
-				$array[$key] = $this->conv($array[$key],$fromCS,$toCS,$useEntityForNoChar);
+				$array[$key] = $this->conv($array[$key], $fromCS, $toCS, $useEntityForNoChar);
 			}
 		}
 	}
@@ -677,39 +686,47 @@
 	 * @param	string		Charset, lowercase. Must be found in csconvtbl/ folder.
 	 * @return	string		Output string, converted to UTF-8
 	 */
-	function utf8_encode($str,$charset)	{
+	function utf8_encode($str, $charset) {
 
-		if ($charset === 'utf-8')	return $str;
+		if ($charset === 'utf-8') {
+			return $str;
+		}
 
 			// Charset is case-insensitive.
-		if ($this->initCharset($charset))	{	// Parse conv. table if not already...
+		if ($this->initCharset($charset)) { // Parse conv. table if not already...
 			$strLen = strlen($str);
-			$outStr='';
+			$outStr = '';
 
-			for ($a=0;$a<$strLen;$a++)	{	// Traverse each char in string.
+			for ($a = 0; $a < $strLen; $a++) { // Traverse each char in string.
-				$chr=substr($str,$a,1);
+				$chr = substr($str, $a, 1);
-				$ord=ord($chr);
+				$ord = ord($chr);
-				if (isset($this->twoByteSets[$charset]))	{	// If the charset has two bytes per char
+				if (isset($this->twoByteSets[$charset])) { // If the charset has two bytes per char
-					$ord2 = ord($str{$a+1});
+					$ord2 = ord($str{$a + 1});
-					$ord = $ord<<8 | $ord2; // assume big endian
+					$ord = $ord << 8 | $ord2; // assume big endian
 
-					if (isset($this->parsedCharsets[$charset]['local'][$ord]))	{	// If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?)
+					if (isset($this->parsedCharsets[$charset]['local'][$ord])) { // If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?)
-						$outStr.=$this->parsedCharsets[$charset]['local'][$ord];
+						$outStr .= $this->parsedCharsets[$charset]['local'][$ord];
-					} else $outStr.=chr($this->noCharByteVal);	// No char exists
+					} else {
+						$outStr .= chr($this->noCharByteVal);
+					} // No char exists
 					$a++;
-				} elseif ($ord>127)	{	// If char has value over 127 it's a multibyte char in UTF-8
+				} elseif ($ord > 127) { // If char has value over 127 it's a multibyte char in UTF-8
-					if (isset($this->eucBasedSets[$charset]))	{	// EUC uses two-bytes above 127; we get both and advance pointer and make $ord a 16bit int.
+					if (isset($this->eucBasedSets[$charset])) { // EUC uses two-bytes above 127; we get both and advance pointer and make $ord a 16bit int.
-						if ($charset != 'shift_jis' || ($ord < 0xA0 || $ord > 0xDF))	{	// Shift-JIS: chars between 160 and 223 are single byte
+						if ($charset != 'shift_jis' || ($ord < 0xA0 || $ord > 0xDF)) { // Shift-JIS: chars between 160 and 223 are single byte
 							$a++;
-							$ord2=ord(substr($str,$a,1));
+							$ord2 = ord(substr($str, $a, 1));
-							$ord = $ord*256+$ord2;
+							$ord = $ord * 256 + $ord2;
 						}
 					}
 
-					if (isset($this->parsedCharsets[$charset]['local'][$ord]))	{	// If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?)
+					if (isset($this->parsedCharsets[$charset]['local'][$ord])) { // If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?)
-						$outStr.= $this->parsedCharsets[$charset]['local'][$ord];
+						$outStr .= $this->parsedCharsets[$charset]['local'][$ord];
-					} else $outStr.= chr($this->noCharByteVal);	// No char exists
-				} else $outStr.= $chr;	// ... otherwise it's just ASCII 0-127 and one byte. Transparent
+					} else {
+						$outStr .= chr($this->noCharByteVal);
+					} // No char exists
+				} else {
+					$outStr .= $chr;
+				} // ... otherwise it's just ASCII 0-127 and one byte. Transparent
 			}
 			return $outStr;
 		}
@@ -723,42 +740,52 @@
 	 * @param	boolean		If set, then characters that are not available in the destination character set will be encoded as numeric entities
 	 * @return	string		Output string, converted to local charset
 	 */
-	function utf8_decode($str,$charset,$useEntityForNoChar=0)	{
+	function utf8_decode($str, $charset, $useEntityForNoChar = 0) {
 
 		if ($charset === 'utf-8') {
 			return $str;
 		}
 
 			// Charset is case-insensitive.
-		if ($this->initCharset($charset))	{	// Parse conv. table if not already...
+		if ($this->initCharset($charset)) { // Parse conv. table if not already...
 			$strLen = strlen($str);
-			$outStr='';
+			$outStr = '';
-			$buf='';
+			$buf = '';
-			for ($a=0,$i=0;$a<$strLen;$a++,$i++)	{	// Traverse each char in UTF-8 string.
+			for ($a = 0, $i = 0; $a < $strLen; $a++, $i++) { // Traverse each char in UTF-8 string.
-				$chr=substr($str,$a,1);
+				$chr = substr($str, $a, 1);
-				$ord=ord($chr);
+				$ord = ord($chr);
-				if ($ord>127)	{	// This means multibyte! (first byte!)
+				if ($ord > 127) { // This means multibyte! (first byte!)
-					if ($ord & 64)	{	// Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
+					if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
 
-						$buf=$chr;	// Add first byte
+						$buf = $chr; // Add first byte
-						for ($b=0;$b<8;$b++)	{	// for each byte in multibyte string...
+						for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string...
-							$ord = $ord << 1;	// Shift it left and ...
+							$ord = $ord << 1; // Shift it left and ...
-							if ($ord & 128)	{	// ... and with 8th bit - if that is set, then there are still bytes in sequence.
+							if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence.
-								$a++;	// Increase pointer...
+								$a++; // Increase pointer...
-								$buf.=substr($str,$a,1);	// ... and add the next char.
+								$buf .= substr($str, $a, 1); // ... and add the next char.
-							} else break;
+							} else {
+								break;
-						}
+							}
+						}
 
-						if (isset($this->parsedCharsets[$charset]['utf8'][$buf]))	{	// If the UTF-8 char-sequence is found then...
+						if (isset($this->parsedCharsets[$charset]['utf8'][$buf])) { // If the UTF-8 char-sequence is found then...
-							$mByte = $this->parsedCharsets[$charset]['utf8'][$buf];	// The local number
+							$mByte = $this->parsedCharsets[$charset]['utf8'][$buf]; // The local number
-							if ($mByte>255)	{	// If the local number is greater than 255 we will need to split the byte (16bit word assumed) in two chars.
+							if ($mByte > 255) { // If the local number is greater than 255 we will need to split the byte (16bit word assumed) in two chars.
-								$outStr.= chr(($mByte >> 8) & 255).chr($mByte & 255);
+								$outStr .= chr(($mByte >> 8) & 255) . chr($mByte & 255);
-							} else $outStr.= chr($mByte);
+							} else {
+								$outStr .= chr($mByte);
+							}
-						} elseif ($useEntityForNoChar) {	// Create num entity:
+						} elseif ($useEntityForNoChar) { // Create num entity:
-							$outStr.='&#'.$this->utf8CharToUnumber($buf,1).';';
+							$outStr .= '&#' . $this->utf8CharToUnumber($buf, 1) . ';';
-						} else $outStr.=chr($this->noCharByteVal);	// No char exists
-					} else $outStr.=chr($this->noCharByteVal);	// No char exists (MIDDLE of MB sequence!)
-				} else $outStr.=$chr;	// ... otherwise it's just ASCII 0-127 and one byte. Transparent
+						} else {
+							$outStr .= chr($this->noCharByteVal);
+						} // No char exists
+					} else {
+						$outStr .= chr($this->noCharByteVal);
+					} // No char exists (MIDDLE of MB sequence!)
+				} else {
+					$outStr .= $chr;
+				} // ... otherwise it's just ASCII 0-127 and one byte. Transparent
 			}
 			return $outStr;
 		}
@@ -770,27 +797,33 @@
 	 * @param	string		Input string
 	 * @return	string		Output string
 	 */
-	function utf8_to_entities($str)	{
+	function utf8_to_entities($str) {
 		$strLen = strlen($str);
-		$outStr='';
+		$outStr = '';
-		$buf='';
+		$buf = '';
-		for ($a=0;$a<$strLen;$a++)	{	// Traverse each char in UTF-8 string.
+		for ($a = 0; $a < $strLen; $a++) { // Traverse each char in UTF-8 string.
-			$chr=substr($str,$a,1);
+			$chr = substr($str, $a, 1);
-			$ord=ord($chr);
+			$ord = ord($chr);
-			if ($ord>127)	{	// This means multibyte! (first byte!)
+			if ($ord > 127) { // This means multibyte! (first byte!)
-				if ($ord & 64)	{	// Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
+				if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
-					$buf=$chr;	// Add first byte
+					$buf = $chr; // Add first byte
-					for ($b=0;$b<8;$b++)	{	// for each byte in multibyte string...
+					for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string...
-						$ord = $ord << 1;	// Shift it left and ...
+						$ord = $ord << 1; // Shift it left and ...
-						if ($ord & 128)	{	// ... and with 8th bit - if that is set, then there are still bytes in sequence.
+						if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence.
-							$a++;	// Increase pointer...
+							$a++; // Increase pointer...
-							$buf.=substr($str,$a,1);	// ... and add the next char.
+							$buf .= substr($str, $a, 1); // ... and add the next char.
-						} else break;
+						} else {
+							break;
-					}
+						}
+					}
 
-					$outStr.='&#'.$this->utf8CharToUnumber($buf,1).';';
+					$outStr .= '&#' . $this->utf8CharToUnumber($buf, 1) . ';';
-				} else $outStr.=chr($this->noCharByteVal);	// No char exists (MIDDLE of MB sequence!)
-			} else $outStr.=$chr;	// ... otherwise it's just ASCII 0-127 and one byte. Transparent
+				} else {
+					$outStr .= chr($this->noCharByteVal);
+				} // No char exists (MIDDLE of MB sequence!)
+			} else {
+				$outStr .= $chr;
+			} // ... otherwise it's just ASCII 0-127 and one byte. Transparent
 		}
 
 		return $outStr;
@@ -803,30 +836,30 @@
 	 * @param	boolean		If set, then all string-HTML entities (like &amp; or &pound; will be converted as well)
 	 * @return	string		Output string
 	 */
-	function entities_to_utf8($str,$alsoStdHtmlEnt=0)	{
+	function entities_to_utf8($str, $alsoStdHtmlEnt = 0) {
-		if ($alsoStdHtmlEnt)	{
+		if ($alsoStdHtmlEnt) {
-			$trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES));		// Getting them in iso-8859-1 - but thats ok since this is observed below.
+			$trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES)); // Getting them in iso-8859-1 - but thats ok since this is observed below.
 		}
 
 		$token = md5(microtime());
 		$parts = explode($token, preg_replace('/(&([#[:alnum:]]*);)/', $token . '${2}' . $token, $str));
-		foreach($parts as $k => $v)	{
+		foreach ($parts as $k => $v) {
-			if ($k%2)	{
+			if ($k % 2) {
-				if (substr($v,0,1)=='#')	{	// Dec or hex entities:
+				if (substr($v, 0, 1) == '#') { // Dec or hex entities:
-					if (substr($v,1,1)=='x')	{
+					if (substr($v, 1, 1) == 'x') {
-						$parts[$k] = $this->UnumberToChar(hexdec(substr($v,2)));
+						$parts[$k] = $this->UnumberToChar(hexdec(substr($v, 2)));
 					} else {
-						$parts[$k] = $this->UnumberToChar(substr($v,1));
+						$parts[$k] = $this->UnumberToChar(substr($v, 1));
 					}
-				} elseif ($alsoStdHtmlEnt && $trans_tbl['&'.$v.';']) {	// Other entities:
+				} elseif ($alsoStdHtmlEnt && $trans_tbl['&' . $v . ';']) { // Other entities:
-					$parts[$k] = $this->utf8_encode($trans_tbl['&'.$v.';'],'iso-8859-1');
+					$parts[$k] = $this->utf8_encode($trans_tbl['&' . $v . ';'], 'iso-8859-1');
-				} else {	// No conversion:
+				} else { // No conversion:
-					$parts[$k] ='&'.$v.';';
+					$parts[$k] = '&' . $v . ';';
 				}
 			}
 		}
 
-		return implode('',$parts);
+		return implode('', $parts);
 	}
 
 	/**
@@ -837,32 +870,38 @@
 	 * @param	boolean		If set, then instead of integer numbers the real UTF-8 char is returned.
 	 * @return	array		Output array with the char numbers
 	 */
-	function utf8_to_numberarray($str,$convEntities=0,$retChar=0)	{
+	function utf8_to_numberarray($str, $convEntities = 0, $retChar = 0) {
 			// If entities must be registered as well...:
-		if ($convEntities)	{
+		if ($convEntities) {
-			$str = $this->entities_to_utf8($str,1);
+			$str = $this->entities_to_utf8($str, 1);
 		}
 			// Do conversion:
 		$strLen = strlen($str);
-		$outArr=array();
+		$outArr = array();
-		$buf='';
+		$buf = '';
-		for ($a=0;$a<$strLen;$a++)	{	// Traverse each char in UTF-8 string.
+		for ($a = 0; $a < $strLen; $a++) { // Traverse each char in UTF-8 string.
-			$chr=substr($str,$a,1);
+			$chr = substr($str, $a, 1);
-			$ord=ord($chr);
+			$ord = ord($chr);
-			if ($ord>127)	{	// This means multibyte! (first byte!)
+			if ($ord > 127) { // This means multibyte! (first byte!)
-				if ($ord & 64)	{	// Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
+				if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
-					$buf=$chr;	// Add first byte
+					$buf = $chr; // Add first byte
-					for ($b=0;$b<8;$b++)	{	// for each byte in multibyte string...
+					for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string...
-						$ord = $ord << 1;	// Shift it left and ...
+						$ord = $ord << 1; // Shift it left and ...
-						if ($ord & 128)	{	// ... and with 8th bit - if that is set, then there are still bytes in sequence.
+						if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence.
-							$a++;	// Increase pointer...
+							$a++; // Increase pointer...
-							$buf.=substr($str,$a,1);	// ... and add the next char.
+							$buf .= substr($str, $a, 1); // ... and add the next char.
-						} else break;
+						} else {
+							break;
-					}
+						}
+					}
 
-					$outArr[]=$retChar?$buf:$this->utf8CharToUnumber($buf);
+					$outArr[] = $retChar ? $buf : $this->utf8CharToUnumber($buf);
-				} else $outArr[]=$retChar?chr($this->noCharByteVal):$this->noCharByteVal;	// No char exists (MIDDLE of MB sequence!)
-			} else $outArr[]=$retChar?chr($ord):$ord;	// ... otherwise it's just ASCII 0-127 and one byte. Transparent
+				} else {
+					$outArr[] = $retChar ? chr($this->noCharByteVal) : $this->noCharByteVal;
+				} // No char exists (MIDDLE of MB sequence!)
+			} else {
+				$outArr[] = $retChar ? chr($ord) : $ord;
+			} // ... otherwise it's just ASCII 0-127 and one byte. Transparent
 		}
 
 		return $outArr;
@@ -876,50 +915,60 @@
 	 * The binary representation of the character's integer value is thus simply spread across the bytes and the number of high bits set in the lead byte announces the number of bytes in the multibyte sequence:
 	 *
 	 *  bytes | bits | representation
-	 *      1 |    7 | 0vvvvvvv
+	 *	  1 |	7 | 0vvvvvvv
-	 *      2 |   11 | 110vvvvv 10vvvvvv
+	 *	  2 |   11 | 110vvvvv 10vvvvvv
-	 *      3 |   16 | 1110vvvv 10vvvvvv 10vvvvvv
+	 *	  3 |   16 | 1110vvvv 10vvvvvv 10vvvvvv
-	 *      4 |   21 | 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
+	 *	  4 |   21 | 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
-	 *      5 |   26 | 111110vv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
+	 *	  5 |   26 | 111110vv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
-	 *      6 |   31 | 1111110v 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
+	 *	  6 |   31 | 1111110v 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
 	 *
 	 * @param	integer		UNICODE integer
 	 * @return	string		UTF-8 multibyte character string
 	 * @see utf8CharToUnumber()
 	 */
-	function UnumberToChar($cbyte)	{
+	function UnumberToChar($cbyte) {
-		$str='';
+		$str = '';
 
 		if ($cbyte < 0x80) {
-			$str.=chr($cbyte);
+			$str .= chr($cbyte);
-		} else if ($cbyte < 0x800) {
+		} else {
+			if ($cbyte < 0x800) {
-			$str.=chr(0xC0 | ($cbyte >> 6));
+				$str .= chr(0xC0 | ($cbyte >> 6));
-			$str.=chr(0x80 | ($cbyte & 0x3F));
+				$str .= chr(0x80 | ($cbyte & 0x3F));
-		} else if ($cbyte < 0x10000) {
+			} else {
+				if ($cbyte < 0x10000) {
-			$str.=chr(0xE0 | ($cbyte >> 12));
+					$str .= chr(0xE0 | ($cbyte >> 12));
-			$str.=chr(0x80 | (($cbyte >> 6) & 0x3F));
+					$str .= chr(0x80 | (($cbyte >> 6) & 0x3F));
-			$str.=chr(0x80 | ($cbyte & 0x3F));
+					$str .= chr(0x80 | ($cbyte & 0x3F));
-		} else if ($cbyte < 0x200000) {
+				} else {
+					if ($cbyte < 0x200000) {
-			$str.=chr(0xF0 | ($cbyte >> 18));
+						$str .= chr(0xF0 | ($cbyte >> 18));
-			$str.=chr(0x80 | (($cbyte >> 12) & 0x3F));
+						$str .= chr(0x80 | (($cbyte >> 12) & 0x3F));
-			$str.=chr(0x80 | (($cbyte >> 6) & 0x3F));
+						$str .= chr(0x80 | (($cbyte >> 6) & 0x3F));
-			$str.=chr(0x80 | ($cbyte & 0x3F));
+						$str .= chr(0x80 | ($cbyte & 0x3F));
-		} else if ($cbyte < 0x4000000) {
+					} else {
+						if ($cbyte < 0x4000000) {
-			$str.=chr(0xF8 | ($cbyte >> 24));
+							$str .= chr(0xF8 | ($cbyte >> 24));
-			$str.=chr(0x80 | (($cbyte >> 18) & 0x3F));
+							$str .= chr(0x80 | (($cbyte >> 18) & 0x3F));
-			$str.=chr(0x80 | (($cbyte >> 12) & 0x3F));
+							$str .= chr(0x80 | (($cbyte >> 12) & 0x3F));
-			$str.=chr(0x80 | (($cbyte >> 6) & 0x3F));
+							$str .= chr(0x80 | (($cbyte >> 6) & 0x3F));
-			$str.=chr(0x80 | ($cbyte & 0x3F));
+							$str .= chr(0x80 | ($cbyte & 0x3F));
-		} else if ($cbyte < 0x80000000) {
+						} else {
+							if ($cbyte < 0x80000000) {
-			$str.=chr(0xFC | ($cbyte >> 30));
+								$str .= chr(0xFC | ($cbyte >> 30));
-			$str.=chr(0x80 | (($cbyte >> 24) & 0x3F));
+								$str .= chr(0x80 | (($cbyte >> 24) & 0x3F));
-			$str.=chr(0x80 | (($cbyte >> 18) & 0x3F));
+								$str .= chr(0x80 | (($cbyte >> 18) & 0x3F));
-			$str.=chr(0x80 | (($cbyte >> 12) & 0x3F));
+								$str .= chr(0x80 | (($cbyte >> 12) & 0x3F));
-			$str.=chr(0x80 | (($cbyte >> 6) & 0x3F));
+								$str .= chr(0x80 | (($cbyte >> 6) & 0x3F));
-			$str.=chr(0x80 | ($cbyte & 0x3F));
+								$str .= chr(0x80 | ($cbyte & 0x3F));
-		} else { // Cannot express a 32-bit character in UTF-8
-			$str .= chr($this->noCharByteVal);
-		}
+							} else { // Cannot express a 32-bit character in UTF-8
+								$str .= chr($this->noCharByteVal);
+							}
+						}
+					}
+				}
+			}
+		}
 		return $str;
 	}
 
@@ -932,33 +981,30 @@
 	 * @return	integer		UNICODE integer
 	 * @see UnumberToChar()
 	 */
-	function utf8CharToUnumber($str,$hex=0)	{
+	function utf8CharToUnumber($str, $hex = 0) {
-		$ord=ord(substr($str,0,1));	// First char
+		$ord = ord(substr($str, 0, 1)); // First char
 
-		if (($ord & 192) == 192)	{	// This verifyes that it IS a multi byte string
+		if (($ord & 192) == 192) { // This verifyes that it IS a multi byte string
-			$binBuf='';
+			$binBuf = '';
-			for ($b=0;$b<8;$b++)	{	// for each byte in multibyte string...
+			for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string...
-				$ord = $ord << 1;	// Shift it left and ...
+				$ord = $ord << 1; // Shift it left and ...
-				if ($ord & 128)	{	// ... and with 8th bit - if that is set, then there are still bytes in sequence.
+				if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence.
-					$binBuf.=substr('00000000'.decbin(ord(substr($str,$b+1,1))),-6);
+					$binBuf .= substr('00000000' . decbin(ord(substr($str, $b + 1, 1))), -6);
-				} else break;
+				} else {
+					break;
-			}
+				}
+			}
-			$binBuf=substr('00000000'.decbin(ord(substr($str,0,1))),-(6-$b)).$binBuf;
+			$binBuf = substr('00000000' . decbin(ord(substr($str, 0, 1))), -(6 - $b)) . $binBuf;
 
 			$int = bindec($binBuf);
-		} else $int = $ord;
+		} else {
+			$int = $ord;
+		}
 
-		return $hex ? 'x'.dechex($int) : $int;
+		return $hex ? 'x' . dechex($int) : $int;
 	}
 
 
-
-
-
-
-
-
-
 	/********************************************
 	 *
 	 * Init functions
@@ -975,58 +1021,64 @@
 	 * @return	integer		Returns '1' if already loaded. Returns FALSE if charset conversion table was not found. Returns '2' if the charset conversion table was found and parsed.
 	 * @access private
 	 */
-	function initCharset($charset)	{
+	function initCharset($charset) {
 			// Only process if the charset is not yet loaded:
-		if (!is_array($this->parsedCharsets[$charset]))	{
+		if (!is_array($this->parsedCharsets[$charset])) {
 
 				// Conversion table filename:
-			$charsetConvTableFile = PATH_t3lib.'csconvtbl/'.$charset.'.tbl';
+			$charsetConvTableFile = PATH_t3lib . 'csconvtbl/' . $charset . '.tbl';
 
 				// If the conversion table is found:
-			if ($charset && t3lib_div::validPathStr($charsetConvTableFile) && @is_file($charsetConvTableFile))	{
+			if ($charset && t3lib_div::validPathStr($charsetConvTableFile) && @is_file($charsetConvTableFile)) {
 					// Cache file for charsets:
 					// Caching brought parsing time for gb2312 down from 2400 ms to 150 ms. For other charsets we are talking 11 ms down to zero.
-				$cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/charset_'.$charset.'.tbl');
+				$cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/charset_' . $charset . '.tbl');
-				if ($cacheFile && @is_file($cacheFile))	{
+				if ($cacheFile && @is_file($cacheFile)) {
-					$this->parsedCharsets[$charset]=unserialize(t3lib_div::getUrl($cacheFile));
+					$this->parsedCharsets[$charset] = unserialize(t3lib_div::getUrl($cacheFile));
 				} else {
 						// Parse conversion table into lines:
-					$lines=t3lib_div::trimExplode(LF,t3lib_div::getUrl($charsetConvTableFile),1);
+					$lines = t3lib_div::trimExplode(LF, t3lib_div::getUrl($charsetConvTableFile), 1);
 						// Initialize the internal variable holding the conv. table:
-					$this->parsedCharsets[$charset]=array('local'=>array(),'utf8'=>array());
+					$this->parsedCharsets[$charset] = array('local' => array(), 'utf8' => array());
 						// traverse the lines:
-					$detectedType='';
+					$detectedType = '';
-					foreach($lines as $value)	{
+					foreach ($lines as $value) {
-						if (trim($value) && substr($value,0,1)!='#')	{	// Comment line or blanks are ignored.
+						if (trim($value) && substr($value, 0, 1) != '#') { // Comment line or blanks are ignored.
 
 								// Detect type if not done yet: (Done on first real line)
 								// The "whitespaced" type is on the syntax 	"0x0A	0x000A	#LINE FEED" 	while 	"ms-token" is like 		"B9 = U+00B9 : SUPERSCRIPT ONE"
-							if (!$detectedType)		$detectedType = preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/',$value) ? 'whitespaced' : 'ms-token';
+							if (!$detectedType) {
+								$detectedType = preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/', $value) ? 'whitespaced' : 'ms-token';
+							}
 
-							if ($detectedType=='ms-token')	{
+							if ($detectedType == 'ms-token') {
 								list($hexbyte, $utf8) = preg_split('/[=:]/', $value, 3);
-							} elseif ($detectedType=='whitespaced')	{
+							} elseif ($detectedType == 'whitespaced') {
-								$regA=array();
+								$regA = array();
-								preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/',$value,$regA);
+								preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/', $value, $regA);
 								$hexbyte = $regA[1];
-								$utf8 = 'U+'.$regA[2];
+								$utf8 = 'U+' . $regA[2];
 							}
 							$decval = hexdec(trim($hexbyte));
-							if ($decval>127)	{
+							if ($decval > 127) {
-								$utf8decval = hexdec(substr(trim($utf8),2));
+								$utf8decval = hexdec(substr(trim($utf8), 2));
-								$this->parsedCharsets[$charset]['local'][$decval]=$this->UnumberToChar($utf8decval);
+								$this->parsedCharsets[$charset]['local'][$decval] = $this->UnumberToChar($utf8decval);
-								$this->parsedCharsets[$charset]['utf8'][$this->parsedCharsets[$charset]['local'][$decval]]=$decval;
+								$this->parsedCharsets[$charset]['utf8'][$this->parsedCharsets[$charset]['local'][$decval]] = $decval;
 							}
 						}
 					}
-					if ($cacheFile)	{
+					if ($cacheFile) {
-						t3lib_div::writeFileToTypo3tempDir($cacheFile,serialize($this->parsedCharsets[$charset]));
+						t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->parsedCharsets[$charset]));
 					}
 				}
 				return 2;
-			} else return false;
-		} else return 1;
+			} else {
+				return FALSE;
-	}
+			}
+		} else {
+			return 1;
+		}
+	}
 
 	/**
 	 * This function initializes all UTF-8 character data tables.
@@ -1037,28 +1089,32 @@
 	 * @return	integer		Returns FALSE on error, a TRUE value on success: 1 table already loaded, 2, cached version, 3 table parsed (and cached).
 	 * @access private
 	 */
-	function initUnicodeData($mode=null)	{
+	function initUnicodeData($mode = NULL) {
 			// cache files
 		$cacheFileCase = t3lib_div::getFileAbsFileName('typo3temp/cs/cscase_utf-8.tbl');
 		$cacheFileASCII = t3lib_div::getFileAbsFileName('typo3temp/cs/csascii_utf-8.tbl');
 
 			// Only process if the tables are not yet loaded
-		switch($mode)	{
+		switch ($mode) {
 			case 'case':
-				if (is_array($this->caseFolding['utf-8']))	return 1;
+				if (is_array($this->caseFolding['utf-8'])) {
+					return 1;
+				}
 
 					// Use cached version if possible
-				if ($cacheFileCase && @is_file($cacheFileCase))	{
+				if ($cacheFileCase && @is_file($cacheFileCase)) {
 					$this->caseFolding['utf-8'] = unserialize(t3lib_div::getUrl($cacheFileCase));
 					return 2;
 				}
 				break;
 
 			case 'ascii':
-				if (is_array($this->toASCII['utf-8']))	return 1;
+				if (is_array($this->toASCII['utf-8'])) {
+					return 1;
+				}
 
 					// Use cached version if possible
-				if ($cacheFileASCII && @is_file($cacheFileASCII))	{
+				if ($cacheFileASCII && @is_file($cacheFileASCII)) {
 					$this->toASCII['utf-8'] = unserialize(t3lib_div::getUrl($cacheFileASCII));
 					return 2;
 				}
@@ -1066,11 +1122,15 @@
 		}
 
 			// process main Unicode data file
-		$unicodeDataFile = PATH_t3lib.'unidata/UnicodeData.txt';
+		$unicodeDataFile = PATH_t3lib . 'unidata/UnicodeData.txt';
-		if (!(t3lib_div::validPathStr($unicodeDataFile) && @is_file($unicodeDataFile)))	return false;
+		if (!(t3lib_div::validPathStr($unicodeDataFile) && @is_file($unicodeDataFile))) {
+			return FALSE;
+		}
 
-		$fh = fopen($unicodeDataFile,'rb');
+		$fh = fopen($unicodeDataFile, 'rb');
-		if (!$fh)	return false;
+		if (!$fh) {
+			return FALSE;
+		}
 
 			// key = utf8 char (single codepoint), value = utf8 string (codepoint sequence)
 			// note: we use the UTF-8 characters here and not the Unicode numbers to avoid conversion roundtrip in utf8_strtolower/-upper)
@@ -1080,58 +1140,72 @@
 		$utf8CaseFolding['toLower'] = array();
 		$utf8CaseFolding['toTitle'] = array();
 
-		$decomposition = array();	// array of temp. decompositions
+		$decomposition = array(); // array of temp. decompositions
-		$mark = array();		// array of chars that are marks (eg. composing accents)
+		$mark = array(); // array of chars that are marks (eg. composing accents)
-		$number = array();		// array of chars that are numbers (eg. digits)
+		$number = array(); // array of chars that are numbers (eg. digits)
-		$omit = array();		// array of chars to be omitted (eg. Russian hard sign)
+		$omit = array(); // array of chars to be omitted (eg. Russian hard sign)
 
-		while (!feof($fh))	{
+		while (!feof($fh)) {
-			$line = fgets($fh,4096);
+			$line = fgets($fh, 4096);
 				// has a lot of info
-			list($char,$name,$cat,,,$decomp,,,$num,,,,$upper,$lower,$title,) = explode(';', rtrim($line));
+			list($char, $name, $cat, , , $decomp, , , $num, , , , $upper, $lower, $title,) = explode(';', rtrim($line));
 
 			$ord = hexdec($char);
-			if ($ord > 0xFFFF)	break;	// only process the BMP
+			if ($ord > 0xFFFF) {
+				break;
+			} // only process the BMP
 
 			$utf8_char = $this->UnumberToChar($ord);
 
-			if ($upper)	$utf8CaseFolding['toUpper'][$utf8_char] = $this->UnumberToChar(hexdec($upper));
-			if ($lower)	$utf8CaseFolding['toLower'][$utf8_char] = $this->UnumberToChar(hexdec($lower));
+			if ($upper) {
+				$utf8CaseFolding['toUpper'][$utf8_char] = $this->UnumberToChar(hexdec($upper));
+			}
+			if ($lower) {
+				$utf8CaseFolding['toLower'][$utf8_char] = $this->UnumberToChar(hexdec($lower));
+			}
 				// store "title" only when different from "upper" (only a few)
-			if ($title && $title != $upper)	$utf8CaseFolding['toTitle'][$utf8_char] = $this->UnumberToChar(hexdec($title));
+			if ($title && $title != $upper) {
+				$utf8CaseFolding['toTitle'][$utf8_char] = $this->UnumberToChar(hexdec($title));
+			}
 
-			switch ($cat{0})	{
+			switch ($cat{0}) {
-				case 'M':	// mark (accent, umlaut, ...)
+				case 'M': // mark (accent, umlaut, ...)
 					$mark["U+$char"] = 1;
 					break;
 
-				case 'N':	// numeric value
+				case 'N': // numeric value
-					if ($ord > 0x80 && $num != '')	$number["U+$char"] = $num;
+					if ($ord > 0x80 && $num != '') {
+						$number["U+$char"] = $num;
-			}
+					}
+			}
 
 				// accented Latin letters without "official" decomposition
 			$match = array();
-			if (preg_match('/^LATIN (SMALL|CAPITAL) LETTER ([A-Z]) WITH/',$name,$match) && !$decomp)	{
+			if (preg_match('/^LATIN (SMALL|CAPITAL) LETTER ([A-Z]) WITH/', $name, $match) && !$decomp) {
 				$c = ord($match[2]);
-				if ($match[1] == 'SMALL')	$c += 32;
+				if ($match[1] == 'SMALL') {
+					$c += 32;
+				}
 
 				$decomposition["U+$char"] = array(dechex($c));
 				continue;
 			}
 
 			$match = array();
-			if (preg_match('/(<.*>)? *(.+)/',$decomp,$match))	{
+			if (preg_match('/(<.*>)? *(.+)/', $decomp, $match)) {
-				switch($match[1])	{
+				switch ($match[1]) {
-					case '<circle>':	// add parenthesis as circle replacement, eg (1)
+					case '<circle>': // add parenthesis as circle replacement, eg (1)
-						$match[2] = '0028 '.$match[2].' 0029';
+						$match[2] = '0028 ' . $match[2] . ' 0029';
 						break;
 
-					case '<square>':	// add square brackets as square replacement, eg [1]
+					case '<square>': // add square brackets as square replacement, eg [1]
-						$match[2] = '005B '.$match[2].' 005D';
+						$match[2] = '005B ' . $match[2] . ' 005D';
 						break;
 
-					case '<compat>':	// ignore multi char decompositions that start with a space
+					case '<compat>': // ignore multi char decompositions that start with a space
-						if (preg_match('/^0020 /',$match[2]))	continue 2;
+						if (preg_match('/^0020 /', $match[2])) {
+							continue 2;
+						}
 						break;
 
 						// ignore Arabic and vertical layout presentation decomposition
@@ -1148,31 +1222,31 @@
 		fclose($fh);
 
 			// process additional Unicode data for casing (allow folded characters to expand into a sequence)
-		$specialCasingFile = PATH_t3lib.'unidata/SpecialCasing.txt';
+		$specialCasingFile = PATH_t3lib . 'unidata/SpecialCasing.txt';
-		if (t3lib_div::validPathStr($specialCasingFile) && @is_file($specialCasingFile))	{
+		if (t3lib_div::validPathStr($specialCasingFile) && @is_file($specialCasingFile)) {
-			$fh = fopen($specialCasingFile,'rb');
+			$fh = fopen($specialCasingFile, 'rb');
-			if ($fh)	{
+			if ($fh) {
-				while (!feof($fh))	{
+				while (!feof($fh)) {
-					$line = fgets($fh,4096);
+					$line = fgets($fh, 4096);
-					if ($line{0} != '#' && trim($line) != '')	{
+					if ($line{0} != '#' && trim($line) != '') {
 
-						list($char,$lower,$title,$upper,$cond) = t3lib_div::trimExplode(';', $line);
+						list($char, $lower, $title, $upper, $cond) = t3lib_div::trimExplode(';', $line);
-						if ($cond == '' || $cond{0} == '#')	{
+						if ($cond == '' || $cond{0} == '#') {
 							$utf8_char = $this->UnumberToChar(hexdec($char));
-							if ($char != $lower)	{
+							if ($char != $lower) {
 								$arr = explode(' ', $lower);
-								for ($i=0; isset($arr[$i]); $i++)	$arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
+								for ($i = 0; isset($arr[$i]); $i++) $arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
-								$utf8CaseFolding['toLower'][$utf8_char] = implode('',$arr);
+								$utf8CaseFolding['toLower'][$utf8_char] = implode('', $arr);
 							}
-							if ($char != $title && $title != $upper)	{
+							if ($char != $title && $title != $upper) {
 								$arr = explode(' ', $title);
-								for ($i=0; isset($arr[$i]); $i++)	$arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
+								for ($i = 0; isset($arr[$i]); $i++) $arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
-								$utf8CaseFolding['toTitle'][$utf8_char] = implode('',$arr);
+								$utf8CaseFolding['toTitle'][$utf8_char] = implode('', $arr);
 							}
-							if ($char != $upper)	{
+							if ($char != $upper) {
-									$arr = explode(' ', $upper);
+								$arr = explode(' ', $upper);
-								for ($i=0; isset($arr[$i]); $i++)	$arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
+								for ($i = 0; isset($arr[$i]); $i++) $arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
-								$utf8CaseFolding['toUpper'][$utf8_char] = implode('',$arr);
+								$utf8CaseFolding['toUpper'][$utf8_char] = implode('', $arr);
 							}
 						}
 					}
@@ -1182,15 +1256,17 @@
 		}
 
 			// process custom decompositions
-		$customTranslitFile = PATH_t3lib.'unidata/Translit.txt';
+		$customTranslitFile = PATH_t3lib . 'unidata/Translit.txt';
-		if (t3lib_div::validPathStr($customTranslitFile) && @is_file($customTranslitFile))	{
+		if (t3lib_div::validPathStr($customTranslitFile) && @is_file($customTranslitFile)) {
-			$fh = fopen($customTranslitFile,'rb');
+			$fh = fopen($customTranslitFile, 'rb');
-			if ($fh)	{
+			if ($fh) {
-				while (!feof($fh))	{
+				while (!feof($fh)) {
-					$line = fgets($fh,4096);
+					$line = fgets($fh, 4096);
-					if ($line{0} != '#' && trim($line) != '')	{
+					if ($line{0} != '#' && trim($line) != '') {
-						list($char,$translit) = t3lib_div::trimExplode(';', $line);
+						list($char, $translit) = t3lib_div::trimExplode(';', $line);
-						if (!$translit)	$omit["U+$char"] = 1;
+						if (!$translit) {
+							$omit["U+$char"] = 1;
+						}
 						$decomposition["U+$char"] = explode(' ', $translit);
 
 					}
@@ -1200,19 +1276,19 @@
 		}
 
 			// decompose and remove marks; inspired by unac (Loic Dachary <loic@senga.org>)
-		foreach($decomposition as $from => $to)	{
+		foreach ($decomposition as $from => $to) {
 			$code_decomp = array();
 
-			while ($code_value = array_shift($to))	{
+			while ($code_value = array_shift($to)) {
-				if (isset($decomposition["U+$code_value"]))	{	// do recursive decomposition
+				if (isset($decomposition["U+$code_value"])) { // do recursive decomposition
-					foreach(array_reverse($decomposition["U+$code_value"]) as $cv)	{
+					foreach (array_reverse($decomposition["U+$code_value"]) as $cv) {
 						array_unshift($to, $cv);
 					}
-				} elseif (!isset($mark["U+$code_value"])) {	// remove mark
+				} elseif (!isset($mark["U+$code_value"])) { // remove mark
 					array_push($code_decomp, $code_value);
 				}
 			}
-			if (count($code_decomp) || isset($omit[$from]))	{
+			if (count($code_decomp) || isset($omit[$from])) {
 				$decomposition[$from] = $code_decomp;
 			} else {
 				unset($decomposition[$from]);
@@ -1223,32 +1299,35 @@
 		$this->toASCII['utf-8'] = array();
 		$ascii =& $this->toASCII['utf-8'];
 
-		foreach($decomposition as $from => $to)	{
+		foreach ($decomposition as $from => $to) {
 			$code_decomp = array();
-			while ($code_value = array_shift($to))	{
+			while ($code_value = array_shift($to)) {
 				$ord = hexdec($code_value);
-				if ($ord > 127)
-					continue 2;	// skip decompositions containing non-ASCII chars
+				if ($ord > 127) {
+					continue 2;
+				} // skip decompositions containing non-ASCII chars
 				else
+				{
-					array_push($code_decomp,chr($ord));
+					array_push($code_decomp, chr($ord));
-			}
+				}
+			}
-			$ascii[$this->UnumberToChar(hexdec($from))] = join('',$code_decomp);
+			$ascii[$this->UnumberToChar(hexdec($from))] = join('', $code_decomp);
 		}
 
 			// add numeric decompositions
-		foreach($number as $from => $to)	{
+		foreach ($number as $from => $to) {
 			$utf8_char = $this->UnumberToChar(hexdec($from));
-			if (!isset($ascii[$utf8_char]))	{
+			if (!isset($ascii[$utf8_char])) {
 				$ascii[$utf8_char] = $to;
 			}
 		}
 
-		if ($cacheFileCase)	{
+		if ($cacheFileCase) {
-				t3lib_div::writeFileToTypo3tempDir($cacheFileCase,serialize($utf8CaseFolding));
+			t3lib_div::writeFileToTypo3tempDir($cacheFileCase, serialize($utf8CaseFolding));
 		}
 
-		if ($cacheFileASCII)	{
+		if ($cacheFileASCII) {
-				t3lib_div::writeFileToTypo3tempDir($cacheFileASCII,serialize($ascii));
+			t3lib_div::writeFileToTypo3tempDir($cacheFileASCII, serialize($ascii));
 		}
 
 		return 3;
@@ -1262,55 +1341,63 @@
 	 * @return	integer		Returns FALSE on error, a TRUE value on success: 1 table already loaded, 2, cached version, 3 table parsed (and cached).
 	 * @access private
 	 */
-	function initCaseFolding($charset)	{
+	function initCaseFolding($charset) {
 			// Only process if the case table is not yet loaded:
-		if (is_array($this->caseFolding[$charset]))	return 1;
+		if (is_array($this->caseFolding[$charset])) {
+			return 1;
+		}
 
 			// Use cached version if possible
-		$cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/cscase_'.$charset.'.tbl');
+		$cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/cscase_' . $charset . '.tbl');
-		if ($cacheFile && @is_file($cacheFile))	{
+		if ($cacheFile && @is_file($cacheFile)) {
 			$this->caseFolding[$charset] = unserialize(t3lib_div::getUrl($cacheFile));
 			return 2;
 		}
 
 			// init UTF-8 conversion for this charset
-		if (!$this->initCharset($charset))	{
+		if (!$this->initCharset($charset)) {
-			return false;
+			return FALSE;
 		}
 
 			// UTF-8 case folding is used as the base conversion table
-		if (!$this->initUnicodeData('case'))	{
+		if (!$this->initUnicodeData('case')) {
-			return false;
+			return FALSE;
 		}
 
 		$nochar = chr($this->noCharByteVal);
-		foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8)	{
+		foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) {
 				// reconvert to charset (don't use chr() of numeric value, might be muli-byte)
 			$c = $this->utf8_decode($utf8, $charset);
 
 				// $cc = $this->conv($this->caseFolding['utf-8']['toUpper'][$utf8], 'utf-8', $charset);
 			$cc = $this->utf8_decode($this->caseFolding['utf-8']['toUpper'][$utf8], $charset);
-			if ($cc != '' && $cc != $nochar)	$this->caseFolding[$charset]['toUpper'][$c] = $cc;
+			if ($cc != '' && $cc != $nochar) {
+				$this->caseFolding[$charset]['toUpper'][$c] = $cc;
+			}
 
 				// $cc = $this->conv($this->caseFolding['utf-8']['toLower'][$utf8], 'utf-8', $charset);
 			$cc = $this->utf8_decode($this->caseFolding['utf-8']['toLower'][$utf8], $charset);
-			if ($cc != '' && $cc != $nochar)	$this->caseFolding[$charset]['toLower'][$c] = $cc;
+			if ($cc != '' && $cc != $nochar) {
+				$this->caseFolding[$charset]['toLower'][$c] = $cc;
+			}
 
 				// $cc = $this->conv($this->caseFolding['utf-8']['toTitle'][$utf8], 'utf-8', $charset);
 			$cc = $this->utf8_decode($this->caseFolding['utf-8']['toTitle'][$utf8], $charset);
-			if ($cc != '' && $cc != $nochar)	$this->caseFolding[$charset]['toTitle'][$c] = $cc;
+			if ($cc != '' && $cc != $nochar) {
+				$this->caseFolding[$charset]['toTitle'][$c] = $cc;
-		}
+			}
+		}
 
 			// add the ASCII case table
-		for ($i=ord('a'); $i<=ord('z'); $i++)	{
+		for ($i = ord('a'); $i <= ord('z'); $i++) {
-			$this->caseFolding[$charset]['toUpper'][chr($i)] = chr($i-32);
+			$this->caseFolding[$charset]['toUpper'][chr($i)] = chr($i - 32);
 		}
-		for ($i=ord('A'); $i<=ord('Z'); $i++)	{
+		for ($i = ord('A'); $i <= ord('Z'); $i++) {
-			$this->caseFolding[$charset]['toLower'][chr($i)] = chr($i+32);
+			$this->caseFolding[$charset]['toLower'][chr($i)] = chr($i + 32);
 		}
 
-		if ($cacheFile)	{
+		if ($cacheFile) {
-				t3lib_div::writeFileToTypo3tempDir($cacheFile,serialize($this->caseFolding[$charset]));
+			t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->caseFolding[$charset]));
 		}
 
 		return 3;
@@ -1324,59 +1411,47 @@
 	 * @return	integer		Returns FALSE on error, a TRUE value on success: 1 table already loaded, 2, cached version, 3 table parsed (and cached).
 	 * @access private
 	 */
-	function initToASCII($charset)	{
+	function initToASCII($charset) {
 			// Only process if the case table is not yet loaded:
-		if (is_array($this->toASCII[$charset]))	return 1;
+		if (is_array($this->toASCII[$charset])) {
+			return 1;
+		}
 
 			// Use cached version if possible
-		$cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/csascii_'.$charset.'.tbl');
+		$cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/csascii_' . $charset . '.tbl');
-		if ($cacheFile && @is_file($cacheFile))	{
+		if ($cacheFile && @is_file($cacheFile)) {
 			$this->toASCII[$charset] = unserialize(t3lib_div::getUrl($cacheFile));
 			return 2;
 		}
 
 			// init UTF-8 conversion for this charset
-		if (!$this->initCharset($charset))	{
+		if (!$this->initCharset($charset)) {
-			return false;
+			return FALSE;
 		}
 
 			// UTF-8/ASCII transliteration is used as the base conversion table
-		if (!$this->initUnicodeData('ascii'))	{
+		if (!$this->initUnicodeData('ascii')) {
-			return false;
+			return FALSE;
 		}
 
 		$nochar = chr($this->noCharByteVal);
-		foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8)	{
+		foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) {
 				// reconvert to charset (don't use chr() of numeric value, might be muli-byte)
 			$c = $this->utf8_decode($utf8, $charset);
 
-			if (isset($this->toASCII['utf-8'][$utf8]))	{
+			if (isset($this->toASCII['utf-8'][$utf8])) {
 				$this->toASCII[$charset][$c] = $this->toASCII['utf-8'][$utf8];
 			}
 		}
 
-		if ($cacheFile)	{
+		if ($cacheFile) {
-				t3lib_div::writeFileToTypo3tempDir($cacheFile,serialize($this->toASCII[$charset]));
+			t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->toASCII[$charset]));
 		}
 
 		return 3;
 	}
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 	/********************************************
 	 *
 	 * String operation functions
@@ -1395,49 +1470,49 @@
 	 * @see substr(), mb_substr()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function substr($charset,$string,$start,$len=null)	{
+	function substr($charset, $string, $start, $len = NULL) {
 		if ($len === 0 || $string === '') {
 			return '';
 		}
 
-		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring')	{
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
 				// cannot omit $len, when specifying charset
-			if ($len==null)	{
+			if ($len == NULL) {
-				$enc = mb_internal_encoding();	// save internal encoding
+				$enc = mb_internal_encoding(); // save internal encoding
 				mb_internal_encoding($charset);
-				$str = mb_substr($string,$start);
+				$str = mb_substr($string, $start);
-				mb_internal_encoding($enc);	// restore internal encoding
+				mb_internal_encoding($enc); // restore internal encoding
 
 				return $str;
 			}
 			else {
-				return mb_substr($string,$start,$len,$charset);
+				return mb_substr($string, $start, $len, $charset);
 			}
-		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv')	{
+		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') {
 				// cannot omit $len, when specifying charset
-			if ($len==null)	{
+			if ($len == NULL) {
-				$enc = iconv_get_encoding('internal_encoding');	// save internal encoding
+				$enc = iconv_get_encoding('internal_encoding'); // save internal encoding
-				iconv_set_encoding('internal_encoding',$charset);
+				iconv_set_encoding('internal_encoding', $charset);
-				$str = iconv_substr($string,$start);
+				$str = iconv_substr($string, $start);
-				iconv_set_encoding('internal_encoding',$enc);	// restore internal encoding
+				iconv_set_encoding('internal_encoding', $enc); // restore internal encoding
 
 				return $str;
 			}
 			else {
-				return iconv_substr($string,$start,$len,$charset);
+				return iconv_substr($string, $start, $len, $charset);
 			}
-		} elseif ($charset == 'utf-8')	{
+		} elseif ($charset == 'utf-8') {
-			return $this->utf8_substr($string,$start,$len);
+			return $this->utf8_substr($string, $start, $len);
-		} elseif ($this->eucBasedSets[$charset])	{
+		} elseif ($this->eucBasedSets[$charset]) {
-			return $this->euc_substr($string,$start,$charset,$len);
+			return $this->euc_substr($string, $start, $charset, $len);
-		} elseif ($this->twoByteSets[$charset])	{
+		} elseif ($this->twoByteSets[$charset]) {
-			return substr($string,$start*2,$len*2);
+			return substr($string, $start * 2, $len * 2);
-		} elseif ($this->fourByteSets[$charset])	{
+		} elseif ($this->fourByteSets[$charset]) {
-			return substr($string,$start*4,$len*4);
+			return substr($string, $start * 4, $len * 4);
 		}
 
-		// treat everything else as single-byte encoding
+			// treat everything else as single-byte encoding
-		return $len === NULL ? substr($string,$start) : substr($string,$start,$len);
+		return $len === NULL ? substr($string, $start) : substr($string, $start, $len);
 	}
 
 	/**
@@ -1450,21 +1525,21 @@
 	 * @see strlen()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function strlen($charset,$string)	{
+	function strlen($charset, $string) {
-		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring')	{
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
-			return mb_strlen($string,$charset);
+			return mb_strlen($string, $charset);
-		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv')	{
+		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') {
-			return iconv_strlen($string,$charset);
+			return iconv_strlen($string, $charset);
-		} elseif ($charset == 'utf-8')	{
+		} elseif ($charset == 'utf-8') {
 			return $this->utf8_strlen($string);
-		} elseif ($this->eucBasedSets[$charset])	{
+		} elseif ($this->eucBasedSets[$charset]) {
-			return $this->euc_strlen($string,$charset);
+			return $this->euc_strlen($string, $charset);
-		} elseif ($this->twoByteSets[$charset])	{
+		} elseif ($this->twoByteSets[$charset]) {
-			return strlen($string)/2;
+			return strlen($string) / 2;
-		} elseif ($this->fourByteSets[$charset])	{
+		} elseif ($this->fourByteSets[$charset]) {
-			return strlen($string)/4;
+			return strlen($string) / 4;
 		}
-		// treat everything else as single-byte encoding
+			// treat everything else as single-byte encoding
 		return strlen($string);
 	}
 
@@ -1504,49 +1579,53 @@
 	 * @see substr(), mb_strimwidth()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function crop($charset,$string,$len,$crop='')	{
+	function crop($charset, $string, $len, $crop = '') {
 		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
 			return $this->cropMbstring($charset, $string, $len, $crop);
 		}
 
-		if (intval($len) == 0)	return $string;
+		if (intval($len) == 0) {
+			return $string;
+		}
 
-		if ($charset == 'utf-8')	{
+		if ($charset == 'utf-8') {
-			$i = $this->utf8_char2byte_pos($string,$len);
+			$i = $this->utf8_char2byte_pos($string, $len);
-		} elseif ($this->eucBasedSets[$charset])	{
+		} elseif ($this->eucBasedSets[$charset]) {
-			$i = $this->euc_char2byte_pos($string,$len,$charset);
+			$i = $this->euc_char2byte_pos($string, $len, $charset);
 		} else {
-			if ($len > 0)	{
+			if ($len > 0) {
 				$i = $len;
 			} else {
-				$i = strlen($string)+$len;
+				$i = strlen($string) + $len;
-				if ($i<=0)	$i = false;
+				if ($i <= 0) {
+					$i = FALSE;
-			}
-		}
+				}
+			}
+		}
 
-		if ($i === false)	{	// $len outside actual string length
+		if ($i === FALSE) { // $len outside actual string length
 			return $string;
-		} else	{
+		} else {
-			if ($len > 0)	{
+			if ($len > 0) {
-				if (strlen($string{$i}))	{
+				if (strlen($string{$i})) {
-					return substr($string,0,$i).$crop;
+					return substr($string, 0, $i) . $crop;
 
 				}
 			} else {
-				if (strlen($string{$i-1}))	{
+				if (strlen($string{$i - 1})) {
-					return $crop.substr($string,$i);
+					return $crop . substr($string, $i);
 				}
 			}
 
-/*
-			if (abs($len)<$this->strlen($charset,$string))	{	// Has to use ->strlen() - otherwise multibyte strings ending with a multibyte char will return true here (which is not a catastrophe, but...)
-				if ($len > 0)	{
-					return substr($string,0,$i).$crop;
-				} else {
-					return $crop.substr($string,$i);
-				}
-			}
-*/
+			/*
+			   if (abs($len)<$this->strlen($charset,$string))	{	// Has to use ->strlen() - otherwise multibyte strings ending with a multibyte char will return true here (which is not a catastrophe, but...)
+				   if ($len > 0)	{
+					   return substr($string,0,$i).$crop;
+				   } else {
+					   return $crop.substr($string,$i);
+				   }
+			   }
+   */
 		}
 		return $string;
 	}
@@ -1561,23 +1640,27 @@
 	 * @see mb_strcut()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function strtrunc($charset,$string,$len)	{
+	function strtrunc($charset, $string, $len) {
-		if ($len <= 0)	return '';
+		if ($len <= 0) {
+			return '';
+		}
 
-		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring')	{
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
-			return mb_strcut($string,0,$len,$charset);
+			return mb_strcut($string, 0, $len, $charset);
-		} elseif ($charset == 'utf-8')	{
+		} elseif ($charset == 'utf-8') {
-			return $this->utf8_strtrunc($string,$len);
+			return $this->utf8_strtrunc($string, $len);
-		} elseif ($this->eucBasedSets[$charset])	{
+		} elseif ($this->eucBasedSets[$charset]) {
-			return $this->euc_strtrunc($string,$charset);
+			return $this->euc_strtrunc($string, $len, $charset);
-		} elseif ($this->twoByteSets[$charset])	{
+		} elseif ($this->twoByteSets[$charset]) {
-			if ($len % 2)	$len--;		// don't cut at odd positions
+			if ($len % 2) {
+				$len--;
+			} // don't cut at odd positions
-		} elseif ($this->fourByteSets[$charset])	{
+		} elseif ($this->fourByteSets[$charset]) {
 			$x = $len % 4;
-			$len -= $x;	// realign to position dividable by four
+			$len -= $x; // realign to position dividable by four
 		}
-		// treat everything else as single-byte encoding
+			// treat everything else as single-byte encoding
-		return substr($string,0,$len);
+		return substr($string, 0, $len);
 	}
 
 	/**
@@ -1595,20 +1678,20 @@
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 * @see strtolower(), strtoupper()
 	 */
-	function conv_case($charset,$string,$case)	{
+	function conv_case($charset, $string, $case) {
-		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring')	{
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
-			if ($case == 'toLower')	{
+			if ($case == 'toLower') {
-				$string = mb_strtolower($string,$charset);
+				$string = mb_strtolower($string, $charset);
 			} else {
-				$string = mb_strtoupper($string,$charset);
+				$string = mb_strtoupper($string, $charset);
 			}
-		} elseif ($charset == 'utf-8')	{
+		} elseif ($charset == 'utf-8') {
-			$string = $this->utf8_char_mapping($string,'case',$case);
+			$string = $this->utf8_char_mapping($string, 'case', $case);
-		} elseif (isset($this->eucBasedSets[$charset]))	{
+		} elseif (isset($this->eucBasedSets[$charset])) {
-			$string = $this->euc_char_mapping($string,$charset,'case',$case);
+			$string = $this->euc_char_mapping($string, $charset, 'case', $case);
 		} else {
 				// treat everything else as single-byte encoding
-			$string = $this->sb_char_mapping($string,$charset,'case',$case);
+			$string = $this->sb_char_mapping($string, $charset, 'case', $case);
 		}
 
 		return $string;
@@ -1621,14 +1704,14 @@
 	 * @param	string		Input string to convert
 	 * @return	string		The converted string
 	 */
-	function specCharsToASCII($charset,$string)	{
+	function specCharsToASCII($charset, $string) {
-		if ($charset == 'utf-8')	{
+		if ($charset == 'utf-8') {
-			$string = $this->utf8_char_mapping($string,'ascii');
+			$string = $this->utf8_char_mapping($string, 'ascii');
-		} elseif (isset($this->eucBasedSets[$charset]))	{
+		} elseif (isset($this->eucBasedSets[$charset])) {
-			$string = $this->euc_char_mapping($string,$charset,'ascii');
+			$string = $this->euc_char_mapping($string, $charset, 'ascii');
 		} else {
 				// treat everything else as single-byte encoding
-			$string = $this->sb_char_mapping($string,$charset,'ascii');
+			$string = $this->sb_char_mapping($string, $charset, 'ascii');
 		}
 
 		return $string;
@@ -1639,7 +1722,7 @@
 	 * converts the language codes that we get from the client (usually HTTP_ACCEPT_LANGUAGE)
 	 * into a TYPO3-readable language code
 	 * @param	$languageCodesList	list of language codes. something like 'de,en-us;q=0.9,de-de;q=0.7,es-cl;q=0.6,en;q=0.4,es;q=0.3,zh;q=0.1'
-	 * 			see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
+	 *			 see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
 	 * @return	string	a preferred language that TYPO3 supports, or "default" if none found
 	 * @author	Benjamin Mack (benni.typo3.org)
 	 */
@@ -1647,35 +1730,35 @@
 		$allLanguageCodes = array();
 		$selectedLanguage = 'default';
 
-		// get all languages where TYPO3 code is the same as the ISO code
+			// get all languages where TYPO3 code is the same as the ISO code
 		foreach ($this->charSetArray as $typo3Lang => $charSet) {
 			$allLanguageCodes[$typo3Lang] = $typo3Lang;
 		}
 
-		// get all languages where TYPO3 code differs from ISO code
-		// or needs the country part
-		// the iso codes will here overwrite the default typo3 language in the key
+			// get all languages where TYPO3 code differs from ISO code
+			// or needs the country part
+			// the iso codes will here overwrite the default typo3 language in the key
 		foreach ($this->isoArray as $typo3Lang => $isoLang) {
 			$isoLang = join('-', explode('_', $isoLang));
 			$allLanguageCodes[$typo3Lang] = $isoLang;
 		}
 
-		// move the iso codes to the (because we're comparing the keys with "isset" later on)
+			// move the iso codes to the (because we're comparing the keys with "isset" later on)
 		$allLanguageCodes = array_flip($allLanguageCodes);
 
 
 		$preferredLanguages = t3lib_div::trimExplode(',', $languageCodesList);
-		// order the preferred languages after they key
+			// order the preferred languages after they key
 		$sortedPreferredLanguages = array();
 		foreach ($preferredLanguages as $preferredLanguage) {
 			$quality = 1.0;
-			if (strpos($preferredLanguage, ';q=') !== false) {
+			if (strpos($preferredLanguage, ';q=') !== FALSE) {
 				list($preferredLanguage, $quality) = explode(';q=', $preferredLanguage);
 			}
 			$sortedPreferredLanguages[$preferredLanguage] = $quality;
 		}
 
-		// loop through the languages, with the highest priority first
+			// loop through the languages, with the highest priority first
 		arsort($sortedPreferredLanguages, SORT_NUMERIC);
 		foreach ($sortedPreferredLanguages as $preferredLanguage => $quality) {
 			if (isset($allLanguageCodes[$preferredLanguage])) {
@@ -1683,7 +1766,7 @@
 				break;
 			}
 
-			// strip the country code from the end
+				// strip the country code from the end
 			list($preferredLanguage, $preferredCountry) = explode('-', $preferredLanguage);
 			if (isset($allLanguageCodes[$preferredLanguage])) {
 				$selectedLanguage = $allLanguageCodes[$preferredLanguage];
@@ -1697,14 +1780,6 @@
 	}
 
 
-
-
-
-
-
-
-
-
 	/********************************************
 	 *
 	 * Internal string operation functions
@@ -1721,15 +1796,19 @@
 	 * @return	string		the converted string
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function sb_char_mapping($str,$charset,$mode,$opt='')	{
+	function sb_char_mapping($str, $charset, $mode, $opt = '') {
-		switch($mode)	{
+		switch ($mode) {
 			case 'case':
-				if (!$this->initCaseFolding($charset))	return $str;	// do nothing
+				if (!$this->initCaseFolding($charset)) {
+					return $str;
+				} // do nothing
 				$map =& $this->caseFolding[$charset][$opt];
 				break;
 
 			case 'ascii':
-				if (!$this->initToASCII($charset))	return $str;	// do nothing
+				if (!$this->initToASCII($charset)) {
+					return $str;
+				} // do nothing
 				$map =& $this->toASCII[$charset];
 				break;
 
@@ -1738,9 +1817,9 @@
 		}
 
 		$out = '';
-		for($i=0; strlen($str{$i}); $i++)	{
+		for ($i = 0; strlen($str{$i}); $i++) {
 			$c = $str{$i};
-			if (isset($map[$c]))	{
+			if (isset($map[$c])) {
 				$out .= $map[$c];
 			} else {
 				$out .= $c;
@@ -1751,14 +1830,6 @@
 	}
 
 
-
-
-
-
-
-
-
-
 	/********************************************
 	 *
 	 * Internal UTF-8 string operation functions
@@ -1776,29 +1847,37 @@
 	 * @see substr()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_substr($str,$start,$len=null)	{
-		if (!strcmp($len,'0'))	return '';
+	function utf8_substr($str, $start, $len = NULL) {
+		if (!strcmp($len, '0')) {
+			return '';
+		}
 
-		$byte_start = $this->utf8_char2byte_pos($str,$start);
+		$byte_start = $this->utf8_char2byte_pos($str, $start);
-		if ($byte_start === false)	{
+		if ($byte_start === FALSE) {
-			if ($start > 0)	{
+			if ($start > 0) {
-				return false;	// $start outside string length
+				return FALSE; // $start outside string length
 			} else {
 				$start = 0;
 			}
 		}
 
-		$str = substr($str,$byte_start);
+		$str = substr($str, $byte_start);
 
-		if ($len!=null)	{
+		if ($len != NULL) {
-			$byte_end = $this->utf8_char2byte_pos($str,$len);
+			$byte_end = $this->utf8_char2byte_pos($str, $len);
-			if ($byte_end === false)	// $len outside actual string length
-				return $len<0 ? '' : $str;	// When length is less than zero and exceeds, then we return blank string.
+			if ($byte_end === FALSE) // $len outside actual string length
+			{
+				return $len < 0 ? '' : $str;
+			} // When length is less than zero and exceeds, then we return blank string.
 			else
+			{
-				return substr($str,0,$byte_end);
+				return substr($str, 0, $byte_end);
-		}
+			}
-		else	return $str;
-	}
+		}
+		else	{
+			return $str;
+		}
+	}
 
 	/**
 	 * Counts the number of characters of a string in UTF-8.
@@ -1809,15 +1888,19 @@
 	 * @see strlen()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_strlen($str)	{
+	function utf8_strlen($str) {
-		$n=0;
+		$n = 0;
-		for($i=0; strlen($str{$i}); $i++)	{
+		for ($i = 0; strlen($str{$i}); $i++) {
 			$c = ord($str{$i});
-			if (!($c & 0x80))	// single-byte (0xxxxxx)
+			if (!($c & 0x80)) // single-byte (0xxxxxx)
+			{
 				$n++;
+			}
-			elseif (($c & 0xC0) == 0xC0)	// multi-byte starting byte (11xxxxxx)
+			elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx)
+			{
 				$n++;
-		}
+			}
+		}
 		return $n;
 	}
 
@@ -1830,16 +1913,20 @@
 	 * @see mb_strcut()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_strtrunc($str,$len)	{
+	function utf8_strtrunc($str, $len) {
-		$i = $len-1;
+		$i = $len - 1;
 		if (ord($str{$i}) & 0x80) { // part of a multibyte sequence
-			for (; $i>0 && !(ord($str{$i}) & 0x40); $i--)	;	// find the first byte
+			for (; $i > 0 && !(ord($str{$i}) & 0x40); $i--) ; // find the first byte
-			if ($i <= 0)	return ''; // sanity check
+			if ($i <= 0) {
+				return '';
+			} // sanity check
-			for ($bc=0, $mbs=ord($str{$i}); $mbs & 0x80; $mbs = $mbs << 1)	$bc++;	// calculate number of bytes
+			for ($bc = 0, $mbs = ord($str{$i}); $mbs & 0x80; $mbs = $mbs << 1) $bc++; // calculate number of bytes
-			if ($bc+$i > $len)	return substr($str,0,$i);
+			if ($bc + $i > $len) {
+				return substr($str, 0, $i);
+			}
 			// fallthru: multibyte char fits into length
 		}
-		return substr($str,0,$len);
+		return substr($str, 0, $len);
 	}
 
 	/**
@@ -1852,20 +1939,24 @@
 	 * @see strpos()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_strpos($haystack,$needle,$offset=0)	{
+	function utf8_strpos($haystack, $needle, $offset = 0) {
-		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring')	{
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
-			return mb_strpos($haystack,$needle,$offset,'utf-8');
+			return mb_strpos($haystack, $needle, $offset, 'utf-8');
-		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv')	{
+		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') {
-			return iconv_strpos($haystack,$needle,$offset,'utf-8');
+			return iconv_strpos($haystack, $needle, $offset, 'utf-8');
 		}
 
-		$byte_offset = $this->utf8_char2byte_pos($haystack,$offset);
+		$byte_offset = $this->utf8_char2byte_pos($haystack, $offset);
-		if ($byte_offset === false)	return false; // offset beyond string length
+		if ($byte_offset === FALSE) {
+			return FALSE;
+		} // offset beyond string length
 
-		$byte_pos = strpos($haystack,$needle,$byte_offset);
+		$byte_pos = strpos($haystack, $needle, $byte_offset);
-		if ($byte_pos === false)	return false; // needle not found
+		if ($byte_pos === FALSE) {
+			return FALSE;
+		} // needle not found
 
-		return $this->utf8_byte2char_pos($haystack,$byte_pos);
+		return $this->utf8_byte2char_pos($haystack, $byte_pos);
 	}
 
 	/**
@@ -1877,17 +1968,19 @@
 	 * @see strrpos()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_strrpos($haystack,$needle)	{
+	function utf8_strrpos($haystack, $needle) {
-		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring')	{
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
-			return mb_strrpos($haystack,$needle,'utf-8');
+			return mb_strrpos($haystack, $needle, 'utf-8');
-		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv')	{
+		} elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') {
-			return iconv_strrpos($haystack,$needle,'utf-8');
+			return iconv_strrpos($haystack, $needle, 'utf-8');
 		}
 
-		$byte_pos = strrpos($haystack,$needle);
+		$byte_pos = strrpos($haystack, $needle);
-		if ($byte_pos === false)	return false; // needle not found
+		if ($byte_pos === FALSE) {
+			return FALSE;
+		} // needle not found
 
-		return $this->utf8_byte2char_pos($haystack,$byte_pos);
+		return $this->utf8_byte2char_pos($haystack, $byte_pos);
 	}
 
 	/**
@@ -1899,30 +1992,38 @@
 	 * @return	integer		Byte position
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_char2byte_pos($str,$pos)	{
+	function utf8_char2byte_pos($str, $pos) {
-		$n = 0;				// number of characters found
+		$n = 0; // number of characters found
-		$p = abs($pos);		// number of characters wanted
+		$p = abs($pos); // number of characters wanted
 
-		if ($pos >= 0)	{
+		if ($pos >= 0) {
 			$i = 0;
 			$d = 1;
 		} else {
-			$i = strlen($str)-1;
+			$i = strlen($str) - 1;
 			$d = -1;
 		}
 
-		for( ; strlen($str{$i}) && $n<$p; $i+=$d)	{
+		for (; strlen($str{$i}) && $n < $p; $i += $d) {
-			$c = (int)ord($str{$i});
+			$c = (int) ord($str{$i});
-			if (!($c & 0x80))	// single-byte (0xxxxxx)
+			if (!($c & 0x80)) // single-byte (0xxxxxx)
+			{
 				$n++;
+			}
-			elseif (($c & 0xC0) == 0xC0)	// multi-byte starting byte (11xxxxxx)
+			elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx)
+			{
 				$n++;
-		}
+			}
-		if (!strlen($str{$i}))	return false; // offset beyond string length
+		}
+		if (!strlen($str{$i})) {
+			return FALSE;
+		} // offset beyond string length
 
-		if ($pos >= 0)	{
+		if ($pos >= 0) {
 				// skip trailing multi-byte data bytes
-			while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) { $i++; }
+			while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) {
+				$i++;
+			}
 		} else {
 				// correct offset
 			$i++;
@@ -1940,16 +2041,22 @@
 	 * @return	integer		character position
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_byte2char_pos($str,$pos)	{
+	function utf8_byte2char_pos($str, $pos) {
-		$n = 0;	// number of characters
+		$n = 0; // number of characters
-		for($i=$pos; $i>0; $i--)	{
+		for ($i = $pos; $i > 0; $i--) {
-			$c = (int)ord($str{$i});
+			$c = (int) ord($str{$i});
-			if (!($c & 0x80))	// single-byte (0xxxxxx)
+			if (!($c & 0x80)) // single-byte (0xxxxxx)
+			{
 				$n++;
+			}
-			elseif (($c & 0xC0) == 0xC0)	// multi-byte starting byte (11xxxxxx)
+			elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx)
+			{
 				$n++;
-		}
+			}
-		if (!strlen($str{$i}))	return false; // offset beyond string length
+		}
+		if (!strlen($str{$i})) {
+			return FALSE;
+		} // offset beyond string length
 
 		return $n;
 	}
@@ -1963,11 +2070,13 @@
 	 * @return	string		the converted string
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function utf8_char_mapping($str,$mode,$opt='')	{
+	function utf8_char_mapping($str, $mode, $opt = '') {
-		if (!$this->initUnicodeData($mode))	return $str;	// do nothing
+		if (!$this->initUnicodeData($mode)) {
+			return $str;
+		} // do nothing
 
 		$out = '';
-		switch($mode)	{
+		switch ($mode) {
 			case 'case':
 				$map =& $this->caseFolding['utf-8'][$opt];
 				break;
@@ -1980,17 +2089,21 @@
 				return $str;
 		}
 
-		for($i=0; strlen($str{$i}); $i++)	{
+		for ($i = 0; strlen($str{$i}); $i++) {
 			$c = ord($str{$i});
-			if (!($c & 0x80))	// single-byte (0xxxxxx)
+			if (!($c & 0x80)) // single-byte (0xxxxxx)
+			{
 				$mbc = $str{$i};
+			}
-			elseif (($c & 0xC0) == 0xC0)	{	// multi-byte starting byte (11xxxxxx)
+			elseif (($c & 0xC0) == 0xC0) { // multi-byte starting byte (11xxxxxx)
-				for ($bc=0; $c & 0x80; $c = $c << 1) { $bc++; }	// calculate number of bytes
+				for ($bc = 0; $c & 0x80; $c = $c << 1) {
+					$bc++;
+				} // calculate number of bytes
-				$mbc = substr($str,$i,$bc);
+				$mbc = substr($str, $i, $bc);
-				$i += $bc-1;
+				$i += $bc - 1;
 			}
 
-			if (isset($map[$mbc]))	{
+			if (isset($map[$mbc])) {
 				$out .= $map[$mbc];
 			} else {
 				$out .= $mbc;
@@ -2001,22 +2114,6 @@
 	}
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 	/********************************************
 	 *
 	 * Internal EUC string operation functions
@@ -2039,23 +2136,29 @@
 	 * @see mb_strcut()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function euc_strtrunc($str,$len,$charset)	 {
+	function euc_strtrunc($str, $len, $charset) {
 		$sjis = ($charset == 'shift_jis');
-		for ($i=0; strlen($str{$i}) && $i<$len; $i++) {
+		for ($i = 0; strlen($str{$i}) && $i < $len; $i++) {
 			$c = ord($str{$i});
-			if ($sjis)	{
+			if ($sjis) {
-				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0))	$i++;	// advance a double-byte char
+				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) {
+					$i++;
+				} // advance a double-byte char
 			}
-			else	{
+			else {
-				if ($c >= 0x80)	$i++;	// advance a double-byte char
+				if ($c >= 0x80) {
+					$i++;
+				} // advance a double-byte char
 			}
 		}
-		if (!strlen($str{$i}))	return $str;	// string shorter than supplied length
+		if (!strlen($str{$i})) {
+			return $str;
+		} // string shorter than supplied length
 
-		if ($i>$len) {
+		if ($i > $len) {
-			return substr($str,0,$len-1);	// we ended on a first byte
+			return substr($str, 0, $len - 1); // we ended on a first byte
 		} else {
-			return substr($str,0,$len);
+			return substr($str, 0, $len);
 		}
 	}
 
@@ -2069,21 +2172,29 @@
 	 * @return	string		the substring
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function euc_substr($str,$start,$charset,$len=null)	{
+	function euc_substr($str, $start, $charset, $len = NULL) {
-		$byte_start = $this->euc_char2byte_pos($str,$start,$charset);
+		$byte_start = $this->euc_char2byte_pos($str, $start, $charset);
-		if ($byte_start === false)	return false;	// $start outside string length
+		if ($byte_start === FALSE) {
+			return FALSE;
+		} // $start outside string length
 
-		$str = substr($str,$byte_start);
+		$str = substr($str, $byte_start);
 
-		if ($len!=null)	{
+		if ($len != NULL) {
-			$byte_end = $this->euc_char2byte_pos($str,$len,$charset);
+			$byte_end = $this->euc_char2byte_pos($str, $len, $charset);
-			if ($byte_end === false)	// $len outside actual string length
+			if ($byte_end === FALSE) // $len outside actual string length
+			{
 				return $str;
+			}
 			else
+			{
-				return substr($str,0,$byte_end);
+				return substr($str, 0, $byte_end);
-		}
+			}
-		else	return $str;
-	}
+		}
+		else	{
+			return $str;
+		}
+	}
 
 	/**
 	 * Counts the number of characters of a string in the EUC charset family.
@@ -2094,16 +2205,20 @@
 	 * @see strlen()
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function euc_strlen($str,$charset)	 {
+	function euc_strlen($str, $charset) {
 		$sjis = ($charset == 'shift_jis');
-		$n=0;
+		$n = 0;
-		for ($i=0; strlen($str{$i}); $i++) {
+		for ($i = 0; strlen($str{$i}); $i++) {
 			$c = ord($str{$i});
-			if ($sjis)	{
+			if ($sjis) {
-				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0))	$i++;	// advance a double-byte char
+				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) {
+					$i++;
+				} // advance a double-byte char
 			}
-			else	{
+			else {
-				if ($c >= 0x80)	$i++;	// advance a double-byte char
+				if ($c >= 0x80) {
+					$i++;
+				} // advance a double-byte char
 			}
 
 			$n++;
@@ -2121,33 +2236,41 @@
 	 * @return	integer		byte position
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function euc_char2byte_pos($str,$pos,$charset)	{
+	function euc_char2byte_pos($str, $pos, $charset) {
 		$sjis = ($charset == 'shift_jis');
 		$n = 0; // number of characters seen
-		$p = abs($pos);	// number of characters wanted
+		$p = abs($pos); // number of characters wanted
 
-		if ($pos >= 0)	{
+		if ($pos >= 0) {
 			$i = 0;
 			$d = 1;
 		} else {
-			$i = strlen($str)-1;
+			$i = strlen($str) - 1;
 			$d = -1;
 		}
 
-		for ( ; strlen($str{$i}) && $n<$p; $i+=$d) {
+		for (; strlen($str{$i}) && $n < $p; $i += $d) {
 			$c = ord($str{$i});
-			if ($sjis)	{
+			if ($sjis) {
-				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0))	$i+=$d;	// advance a double-byte char
+				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) {
+					$i += $d;
+				} // advance a double-byte char
 			}
-			else	{
+			else {
-				if ($c >= 0x80)	$i+=$d;	// advance a double-byte char
+				if ($c >= 0x80) {
+					$i += $d;
+				} // advance a double-byte char
 			}
 
 			$n++;
 		}
-		if (!strlen($str{$i}))	return false; // offset beyond string length
+		if (!strlen($str{$i})) {
+			return FALSE;
+		} // offset beyond string length
 
-		if ($pos < 0)	$i++;	// correct offset
+		if ($pos < 0) {
+			$i++;
+		} // correct offset
 
 		return $i;
 	}
@@ -2162,15 +2285,19 @@
 	 * @return	string		the converted string
 	 * @author	Martin Kutschker <martin.t.kutschker@blackbox.net>
 	 */
-	function euc_char_mapping($str,$charset,$mode,$opt='')	{
+	function euc_char_mapping($str, $charset, $mode, $opt = '') {
-		switch($mode)	{
+		switch ($mode) {
 			case 'case':
-				if (!$this->initCaseFolding($charset))	return $str;	// do nothing
+				if (!$this->initCaseFolding($charset)) {
+					return $str;
+				} // do nothing
 				$map =& $this->caseFolding[$charset][$opt];
 				break;
 
 			case 'ascii':
-				if (!$this->initToASCII($charset))	return $str;	// do nothing
+				if (!$this->initToASCII($charset)) {
+					return $str;
+				} // do nothing
 				$map =& $this->toASCII[$charset];
 				break;
 
@@ -2180,24 +2307,24 @@
 
 		$sjis = ($charset == 'shift_jis');
 		$out = '';
-		for($i=0; strlen($str{$i}); $i++)	{
+		for ($i = 0; strlen($str{$i}); $i++) {
 			$mbc = $str{$i};
 			$c = ord($mbc);
 
-			if ($sjis)	{
+			if ($sjis) {
-				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0))	{	// a double-byte char
+				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { // a double-byte char
-					$mbc = substr($str,$i,2);
+					$mbc = substr($str, $i, 2);
 					$i++;
 				}
 			}
-			else	{
+			else {
-				if ($c >= 0x80)	{	// a double-byte char
+				if ($c >= 0x80) { // a double-byte char
-					$mbc = substr($str,$i,2);
+					$mbc = substr($str, $i, 2);
 					$i++;
 				}
 			}
 
-			if (isset($map[$mbc]))	{
+			if (isset($map[$mbc])) {
 				$out .= $map[$mbc];
 			} else {
 				$out .= $mbc;
@@ -2209,8 +2336,8 @@
 
 }
 
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_cs.php'])	{
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_cs.php']) {
 	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_cs.php']);
 }
 
-?>
+?>
\ No newline at end of file
