PageRenderTime 44ms CodeModel.GetById 17ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/reports/leaves_reports/output/plugins/PHPExcel/Shared/String.php

https://bitbucket.org/lecturer34/hrmis
PHP | 668 lines | 371 code | 56 blank | 241 comment | 58 complexity | 6d5ba3f0415cc66d9c1608ec47ed2ca0 MD5 | raw file
  1<?php
  2/**
  3 * PHPExcel
  4 *
  5 * Copyright (c) 2006 - 2010 PHPExcel
  6 *
  7 * This library is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU Lesser General Public
  9 * License as published by the Free Software Foundation; either
 10 * version 2.1 of the License, or (at your option) any later version.
 11 *
 12 * This library is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this library; if not, write to the Free Software
 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 20 *
 21 * @category   PHPExcel
 22 * @package    PHPExcel_Shared
 23 * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
 24 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 25 * @version    1.7.5, 2010-12-10
 26 */
 27
 28
 29/**
 30 * PHPExcel_Shared_String
 31 *
 32 * @category   PHPExcel
 33 * @package    PHPExcel_Shared
 34 * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
 35 */
 36class PHPExcel_Shared_String
 37{
 38	/**	Constants				*/
 39	/**	Regular Expressions		*/
 40	//	Fraction
 41	const STRING_REGEXP_FRACTION	= '(-?)(\d+)\s+(\d+\/\d+)';
 42
 43
 44	/**
 45	 * Control characters array
 46	 *
 47	 * @var string[]
 48	 */
 49	private static $_controlCharacters = array();
 50
 51	/**
 52	 * SYLK Characters array
 53	 *
 54	 * $var array
 55	 */
 56	private static $_SYLKCharacters = array();
 57
 58	/**
 59	 * Decimal separator
 60	 *
 61	 * @var string
 62	 */
 63	private static $_decimalSeparator;
 64
 65	/**
 66	 * Thousands separator
 67	 *
 68	 * @var string
 69	 */
 70	private static $_thousandsSeparator;
 71
 72	/**
 73	 * Is mbstring extension avalable?
 74	 *
 75	 * @var boolean
 76	 */
 77	private static $_isMbstringEnabled;
 78
 79	/**
 80	 * Is iconv extension avalable?
 81	 *
 82	 * @var boolean
 83	 */
 84	private static $_isIconvEnabled;
 85
 86	/**
 87	 * Build control characters array
 88	 */
 89	private static function _buildControlCharacters() {
 90		for ($i = 0; $i <= 31; ++$i) {
 91			if ($i != 9 && $i != 10 && $i != 13) {
 92				$find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
 93				$replace = chr($i);
 94				self::$_controlCharacters[$find] = $replace;
 95			}
 96		}
 97	}
 98
 99	/**
100	 * Build SYLK characters array
101	 */
102	private static function _buildSYLKCharacters()
103	{
104		self::$_SYLKCharacters = array(
105			"\x1B 0"  => chr(0),
106			"\x1B 1"  => chr(1),
107			"\x1B 2"  => chr(2),
108			"\x1B 3"  => chr(3),
109			"\x1B 4"  => chr(4),
110			"\x1B 5"  => chr(5),
111			"\x1B 6"  => chr(6),
112			"\x1B 7"  => chr(7),
113			"\x1B 8"  => chr(8),
114			"\x1B 9"  => chr(9),
115			"\x1B :"  => chr(10),
116			"\x1B ;"  => chr(11),
117			"\x1B <"  => chr(12),
118			"\x1B :"  => chr(13),
119			"\x1B >"  => chr(14),
120			"\x1B ?"  => chr(15),
121			"\x1B!0"  => chr(16),
122			"\x1B!1"  => chr(17),
123			"\x1B!2"  => chr(18),
124			"\x1B!3"  => chr(19),
125			"\x1B!4"  => chr(20),
126			"\x1B!5"  => chr(21),
127			"\x1B!6"  => chr(22),
128			"\x1B!7"  => chr(23),
129			"\x1B!8"  => chr(24),
130			"\x1B!9"  => chr(25),
131			"\x1B!:"  => chr(26),
132			"\x1B!;"  => chr(27),
133			"\x1B!<"  => chr(28),
134			"\x1B!="  => chr(29),
135			"\x1B!>"  => chr(30),
136			"\x1B!?"  => chr(31),
137			"\x1B'?"  => chr(127),
138			"\x1B(0"  => '€', // 128 in CP1252
139			"\x1B(2"  => '‚', // 130 in CP1252
140			"\x1B(3"  => 'ƒ', // 131 in CP1252
141			"\x1B(4"  => '„', // 132 in CP1252
142			"\x1B(5"  => '…', // 133 in CP1252
143			"\x1B(6"  => '†', // 134 in CP1252
144			"\x1B(7"  => '‡', // 135 in CP1252
145			"\x1B(8"  => 'ˆ', // 136 in CP1252
146			"\x1B(9"  => '‰', // 137 in CP1252
147			"\x1B(:"  => 'Ĺ ', // 138 in CP1252
148			"\x1B(;"  => '‹', // 139 in CP1252
149			"\x1BNj"  => 'Œ', // 140 in CP1252
150			"\x1B(>"  => 'Ĺ˝', // 142 in CP1252
151			"\x1B)1"  => '‘', // 145 in CP1252
152			"\x1B)2"  => '’', // 146 in CP1252
153			"\x1B)3"  => '“', // 147 in CP1252
154			"\x1B)4"  => '”', // 148 in CP1252
155			"\x1B)5"  => '•', // 149 in CP1252
156			"\x1B)6"  => '–', // 150 in CP1252
157			"\x1B)7"  => '—', // 151 in CP1252
158			"\x1B)8"  => '˜', // 152 in CP1252
159			"\x1B)9"  => '™', // 153 in CP1252
160			"\x1B):"  => 'ĹĄ', // 154 in CP1252
161			"\x1B);"  => '›', // 155 in CP1252
162			"\x1BNz"  => 'œ', // 156 in CP1252
163			"\x1B)>"  => 'Ĺž', // 158 in CP1252
164			"\x1B)?"  => 'Ÿ', // 159 in CP1252
165			"\x1B*0"  => ' ', // 160 in CP1252
166			"\x1BN!"  => 'ÂĄ', // 161 in CP1252
167			"\x1BN\"" => '¢', // 162 in CP1252
168			"\x1BN#"  => 'ÂŁ', // 163 in CP1252
169			"\x1BN("  => '¤', // 164 in CP1252
170			"\x1BN%"  => 'ÂĽ', // 165 in CP1252
171			"\x1B*6"  => 'ÂŚ', // 166 in CP1252
172			"\x1BN'"  => '§', // 167 in CP1252
173			"\x1BNH " => '¨', // 168 in CP1252
174			"\x1BNS"  => 'Š', // 169 in CP1252
175			"\x1BNc"  => 'ÂŞ', // 170 in CP1252
176			"\x1BN+"  => 'ÂŤ', // 171 in CP1252
177			"\x1B*<"  => 'ÂŹ', // 172 in CP1252
178			"\x1B*="  => '­', // 173 in CP1252
179			"\x1BNR"  => 'ÂŽ', // 174 in CP1252
180			"\x1B*?"  => 'ÂŻ', // 175 in CP1252
181			"\x1BN0"  => '°', // 176 in CP1252
182			"\x1BN1"  => 'Âą', // 177 in CP1252
183			"\x1BN2"  => '²', // 178 in CP1252
184			"\x1BN3"  => 'Âł', // 179 in CP1252
185			"\x1BNB " => '´', // 180 in CP1252
186			"\x1BN5"  => 'Âľ', // 181 in CP1252
187			"\x1BN6"  => 'Âś', // 182 in CP1252
188			"\x1BN7"  => '¡', // 183 in CP1252
189			"\x1B+8"  => '¸', // 184 in CP1252
190			"\x1BNQ"  => 'š', // 185 in CP1252
191			"\x1BNk"  => 'Âş', // 186 in CP1252
192			"\x1BN;"  => 'Âť', // 187 in CP1252
193			"\x1BN<"  => 'Âź', // 188 in CP1252
194			"\x1BN="  => '½', // 189 in CP1252
195			"\x1BN>"  => 'ž', // 190 in CP1252
196			"\x1BN?"  => 'Âż', // 191 in CP1252
197			"\x1BNAA" => 'À', // 192 in CP1252
198			"\x1BNBA" => 'Á', // 193 in CP1252
199			"\x1BNCA" => 'Â', // 194 in CP1252
200			"\x1BNDA" => 'Ã', // 195 in CP1252
201			"\x1BNHA" => 'Ä', // 196 in CP1252
202			"\x1BNJA" => 'Å', // 197 in CP1252
203			"\x1BNa"  => 'Æ', // 198 in CP1252
204			"\x1BNKC" => 'Ç', // 199 in CP1252
205			"\x1BNAE" => 'È', // 200 in CP1252
206			"\x1BNBE" => 'É', // 201 in CP1252
207			"\x1BNCE" => 'Ê', // 202 in CP1252
208			"\x1BNHE" => 'Ë', // 203 in CP1252
209			"\x1BNAI" => 'Ì', // 204 in CP1252
210			"\x1BNBI" => 'Í', // 205 in CP1252
211			"\x1BNCI" => 'Î', // 206 in CP1252
212			"\x1BNHI" => 'Ï', // 207 in CP1252
213			"\x1BNb"  => 'Ð', // 208 in CP1252
214			"\x1BNDN" => 'Ñ', // 209 in CP1252
215			"\x1BNAO" => 'Ò', // 210 in CP1252
216			"\x1BNBO" => 'Ó', // 211 in CP1252
217			"\x1BNCO" => 'Ô', // 212 in CP1252
218			"\x1BNDO" => 'Õ', // 213 in CP1252
219			"\x1BNHO" => 'Ö', // 214 in CP1252
220			"\x1B-7"  => '×', // 215 in CP1252
221			"\x1BNi"  => 'Ø', // 216 in CP1252
222			"\x1BNAU" => 'Ù', // 217 in CP1252
223			"\x1BNBU" => 'Ú', // 218 in CP1252
224			"\x1BNCU" => 'Û', // 219 in CP1252
225			"\x1BNHU" => 'Ü', // 220 in CP1252
226			"\x1B-="  => 'Ý', // 221 in CP1252
227			"\x1BNl"  => 'Þ', // 222 in CP1252
228			"\x1BN{"  => 'ß', // 223 in CP1252
229			"\x1BNAa" => 'Ă ', // 224 in CP1252
230			"\x1BNBa" => 'ĂĄ', // 225 in CP1252
231			"\x1BNCa" => 'â', // 226 in CP1252
232			"\x1BNDa" => 'ĂŁ', // 227 in CP1252
233			"\x1BNHa" => 'ä', // 228 in CP1252
234			"\x1BNJa" => 'ĂĽ', // 229 in CP1252
235			"\x1BNq"  => 'ĂŚ', // 230 in CP1252
236			"\x1BNKc" => 'ç', // 231 in CP1252
237			"\x1BNAe" => 'è', // 232 in CP1252
238			"\x1BNBe" => 'ĂŠ', // 233 in CP1252
239			"\x1BNCe" => 'ĂŞ', // 234 in CP1252
240			"\x1BNHe" => 'ĂŤ', // 235 in CP1252
241			"\x1BNAi" => 'ĂŹ', // 236 in CP1252
242			"\x1BNBi" => 'Ă­', // 237 in CP1252
243			"\x1BNCi" => 'ĂŽ', // 238 in CP1252
244			"\x1BNHi" => 'ĂŻ', // 239 in CP1252
245			"\x1BNs"  => 'Ă°', // 240 in CP1252
246			"\x1BNDn" => 'Ăą', // 241 in CP1252
247			"\x1BNAo" => 'ò', // 242 in CP1252
248			"\x1BNBo" => 'Ăł', // 243 in CP1252
249			"\x1BNCo" => 'Ă´', // 244 in CP1252
250			"\x1BNDo" => 'Ăľ', // 245 in CP1252
251			"\x1BNHo" => 'Ăś', // 246 in CP1252
252			"\x1B/7"  => 'á', // 247 in CP1252
253			"\x1BNy"  => 'ø', // 248 in CP1252
254			"\x1BNAu" => 'Ăš', // 249 in CP1252
255			"\x1BNBu" => 'Ăş', // 250 in CP1252
256			"\x1BNCu" => 'Ăť', // 251 in CP1252
257			"\x1BNHu" => 'Ăź', // 252 in CP1252
258			"\x1B/="  => 'Ă˝', // 253 in CP1252
259			"\x1BN|"  => 'Ăž', // 254 in CP1252
260			"\x1BNHy" => 'Ăż', // 255 in CP1252
261		);
262	}
263
264	/**
265	 * Get whether mbstring extension is available
266	 *
267	 * @return boolean
268	 */
269	public static function getIsMbstringEnabled()
270	{
271		if (isset(self::$_isMbstringEnabled)) {
272			return self::$_isMbstringEnabled;
273		}
274
275		self::$_isMbstringEnabled = function_exists('mb_convert_encoding') ?
276			true : false;
277
278		return self::$_isMbstringEnabled;
279	}
280
281	/**
282	 * Get whether iconv extension is available
283	 *
284	 * @return boolean
285	 */
286	public static function getIsIconvEnabled()
287	{
288		if (isset(self::$_isIconvEnabled)) {
289			return self::$_isIconvEnabled;
290		}
291
292		// Fail if iconv doesn't exist
293		if (!function_exists('iconv')) {
294			self::$_isIconvEnabled = false;
295			return false;
296		}
297
298		// Sometimes iconv is not working, and e.g. iconv('UTF-8', 'UTF-16LE', 'x') just returns false,
299		if (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
300			self::$_isIconvEnabled = false;
301			return false;
302		}
303
304		// Sometimes iconv_substr('A', 0, 1, 'UTF-8') just returns false in PHP 5.2.0
305		// we cannot use iconv in that case either (http://bugs.php.net/bug.php?id=37773)
306		if (!@iconv_substr('A', 0, 1, 'UTF-8')) {
307			self::$_isIconvEnabled = false;
308			return false;
309		}
310
311		// CUSTOM: IBM AIX iconv() does not work
312		if ( defined('PHP_OS') && @stristr(PHP_OS, 'AIX')
313				&& defined('ICONV_IMPL') && (@strcasecmp(ICONV_IMPL, 'unknown') == 0)
314				&& defined('ICONV_VERSION') && (@strcasecmp(ICONV_VERSION, 'unknown') == 0) )
315		{
316			self::$_isIconvEnabled = false;
317			return false;
318		}
319
320		// If we reach here no problems were detected with iconv
321		self::$_isIconvEnabled = true;
322		return true;
323	}
324
325	public static function buildCharacterSets() {
326		if(empty(self::$_controlCharacters)) {
327			self::_buildControlCharacters();
328		}
329		if(empty(self::$_SYLKCharacters)) {
330			self::_buildSYLKCharacters();
331		}
332	}
333
334	/**
335	 * Convert from OpenXML escaped control character to PHP control character
336	 *
337	 * Excel 2007 team:
338	 * ----------------
339	 * That's correct, control characters are stored directly in the shared-strings table.
340	 * We do encode characters that cannot be represented in XML using the following escape sequence:
341	 * _xHHHH_ where H represents a hexadecimal character in the character's value...
342	 * So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
343	 * element or in the shared string <t> element.
344	 *
345	 * @param 	string	$value	Value to unescape
346	 * @return 	string
347	 */
348	public static function ControlCharacterOOXML2PHP($value = '') {
349		return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value );
350	}
351
352	/**
353	 * Convert from PHP control character to OpenXML escaped control character
354	 *
355	 * Excel 2007 team:
356	 * ----------------
357	 * That's correct, control characters are stored directly in the shared-strings table.
358	 * We do encode characters that cannot be represented in XML using the following escape sequence:
359	 * _xHHHH_ where H represents a hexadecimal character in the character's value...
360	 * So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
361	 * element or in the shared string <t> element.
362	 *
363	 * @param 	string	$value	Value to escape
364	 * @return 	string
365	 */
366	public static function ControlCharacterPHP2OOXML($value = '') {
367		return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value );
368	}
369
370	/**
371	 * Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters.
372	 *
373	 * @param string $value
374	 * @return string
375	 */
376	public static function SanitizeUTF8($value)
377	{
378		if (self::getIsIconvEnabled()) {
379			$value = @iconv('UTF-8', 'UTF-8', $value);
380			return $value;
381		}
382
383		if (self::getIsMbstringEnabled()) {
384			$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
385			return $value;
386		}
387
388		// else, no conversion
389		return $value;
390	}
391
392	/**
393	 * Check if a string contains UTF8 data
394	 *
395	 * @param string $value
396	 * @return boolean
397	 */
398	public static function IsUTF8($value = '') {
399		return utf8_encode(utf8_decode($value)) === $value;
400	}
401
402	/**
403	 * Formats a numeric value as a string for output in various output writers forcing
404	 * point as decimal separator in case locale is other than English.
405	 *
406	 * @param mixed $value
407	 * @return string
408	 */
409	public static function FormatNumber($value) {
410		if (is_float($value)) {
411			return str_replace(',', '.', $value);
412		}
413		return (string) $value;
414	}
415
416	/**
417	 * Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length)
418	 * Writes the string using uncompressed notation, no rich text, no Asian phonetics
419	 * If mbstring extension is not available, ASCII is assumed, and compressed notation is used
420	 * although this will give wrong results for non-ASCII strings
421	 * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3
422	 *
423	 * @param string $value UTF-8 encoded string
424	 * @return string
425	 */
426	public static function UTF8toBIFF8UnicodeShort($value)
427	{
428		// character count
429		$ln = self::CountCharacters($value, 'UTF-8');
430
431		// option flags
432		$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
433			0x0001 : 0x0000;
434
435		// characters
436		$chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
437
438		$data = pack('CC', $ln, $opt) . $chars;
439		return $data;
440	}
441
442	/**
443	 * Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length)
444	 * Writes the string using uncompressed notation, no rich text, no Asian phonetics
445	 * If mbstring extension is not available, ASCII is assumed, and compressed notation is used
446	 * although this will give wrong results for non-ASCII strings
447	 * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3
448	 *
449	 * @param string $value UTF-8 encoded string
450	 * @return string
451	 */
452	public static function UTF8toBIFF8UnicodeLong($value)
453	{
454		// character count
455		$ln = self::CountCharacters($value, 'UTF-8');
456
457		// option flags
458		$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
459			0x0001 : 0x0000;
460
461		// characters
462		$chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
463
464		$data = pack('vC', $ln, $opt) . $chars;
465		return $data;
466	}
467
468	/**
469	 * Convert string from one encoding to another. First try iconv, then mbstring, or no convertion
470	 *
471	 * @param string $value
472	 * @param string $to Encoding to convert to, e.g. 'UTF-8'
473	 * @param string $from Encoding to convert from, e.g. 'UTF-16LE'
474	 * @return string
475	 */
476	public static function ConvertEncoding($value, $to, $from)
477	{
478		if (self::getIsIconvEnabled()) {
479			$value = iconv($from, $to, $value);
480			return $value;
481		}
482
483		if (self::getIsMbstringEnabled()) {
484			$value = mb_convert_encoding($value, $to, $from);
485			return $value;
486		}
487		if($from == 'UTF-16LE'){
488			return self::utf16_decode($value, false);
489		}else if($from == 'UTF-16BE'){
490			return self::utf16_decode($value);
491		}
492		// else, no conversion
493		return $value;
494	}
495
496	/**
497	 * Decode UTF-16 encoded strings.
498	 *
499	 * Can handle both BOM'ed data and un-BOM'ed data.
500	 * Assumes Big-Endian byte order if no BOM is available.
501	 * This function was taken from http://php.net/manual/en/function.utf8-decode.php
502	 * and $bom_be parameter added.
503	 *
504	 * @param   string  $str  UTF-16 encoded data to decode.
505	 * @return  string  UTF-8 / ISO encoded data.
506	 * @access  public
507	 * @version 0.2 / 2010-05-13
508	 * @author  Rasmus Andersson {@link http://rasmusandersson.se/}
509	 * @author vadik56
510	 */
511	public static function utf16_decode( $str, $bom_be=true ) {
512		if( strlen($str) < 2 ) return $str;
513		$c0 = ord($str{0});
514		$c1 = ord($str{1});
515		if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
516		elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
517		$len = strlen($str);
518		$newstr = '';
519		for($i=0;$i<$len;$i+=2) {
520			if( $bom_be ) { $val = ord($str{$i})   << 4; $val += ord($str{$i+1}); }
521			else {        $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
522			$newstr .= ($val == 0x228) ? "\n" : chr($val);
523		}
524		return $newstr;
525	}
526
527	/**
528	 * Get character count. First try mbstring, then iconv, finally strlen
529	 *
530	 * @param string $value
531	 * @param string $enc Encoding
532	 * @return int Character count
533	 */
534	public static function CountCharacters($value, $enc = 'UTF-8')
535	{
536		if (self::getIsIconvEnabled()) {
537			return iconv_strlen($value, $enc);
538		}
539
540		if (self::getIsMbstringEnabled()) {
541			return mb_strlen($value, $enc);
542		}
543
544		// else strlen
545		return strlen($value);
546	}
547
548	/**
549	 * Get a substring of a UTF-8 encoded string
550	 *
551	 * @param string $pValue UTF-8 encoded string
552	 * @param int $start Start offset
553	 * @param int $length Maximum number of characters in substring
554	 * @return string
555	 */
556	public static function Substring($pValue = '', $pStart = 0, $pLength = 0)
557	{
558		if (self::getIsIconvEnabled()) {
559			return iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
560		}
561
562		if (self::getIsMbstringEnabled()) {
563			return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
564		}
565
566		// else substr
567		return substr($pValue, $pStart, $pLength);
568	}
569
570
571	/**
572	 * Identify whether a string contains a fractional numeric value,
573	 *    and convert it to a numeric if it is
574	 *
575	 * @param string &$operand string value to test
576	 * @return boolean
577	 */
578	public static function convertToNumberIfFraction(&$operand) {
579		if (preg_match('/^'.self::STRING_REGEXP_FRACTION.'$/i', $operand, $match)) {
580			$sign = ($match[1] == '-') ? '-' : '+';
581			$fractionFormula = '='.$sign.$match[2].$sign.$match[3];
582			$operand = PHPExcel_Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
583			return true;
584		}
585		return false;
586	}	//	function convertToNumberIfFraction()
587
588	/**
589	 * Get the decimal separator. If it has not yet been set explicitly, try to obtain number
590	 * formatting information from locale.
591	 *
592	 * @return string
593	 */
594	public static function getDecimalSeparator()
595	{
596		if (!isset(self::$_decimalSeparator)) {
597			$localeconv = localeconv();
598			self::$_decimalSeparator = $localeconv['decimal_point'] != ''
599				? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
600
601			if (self::$_decimalSeparator == '')
602			{
603				// Default to .
604				self::$_decimalSeparator = '.';
605			}
606		}
607		return self::$_decimalSeparator;
608	}
609
610	/**
611	 * Set the decimal separator. Only used by PHPExcel_Style_NumberFormat::toFormattedString()
612	 * to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF
613	 *
614	 * @param string $pValue Character for decimal separator
615	 */
616	public static function setDecimalSeparator($pValue = '.')
617	{
618		self::$_decimalSeparator = $pValue;
619	}
620
621	/**
622	 * Get the thousands separator. If it has not yet been set explicitly, try to obtain number
623	 * formatting information from locale.
624	 *
625	 * @return string
626	 */
627	public static function getThousandsSeparator()
628	{
629		if (!isset(self::$_thousandsSeparator)) {
630			$localeconv = localeconv();
631			self::$_thousandsSeparator = $localeconv['thousands_sep'] != ''
632				? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
633		}
634		return self::$_thousandsSeparator;
635	}
636
637	/**
638	 * Set the thousands separator. Only used by PHPExcel_Style_NumberFormat::toFormattedString()
639	 * to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF
640	 *
641	 * @param string $pValue Character for thousands separator
642	 */
643	public static function setThousandsSeparator($pValue = ',')
644	{
645		self::$_thousandsSeparator = $pValue;
646	}
647
648	/**
649	 * Convert SYLK encoded string to UTF-8
650	 *
651	 * @param string $pValue
652	 * @return string UTF-8 encoded string
653	 */
654	public static function SYLKtoUTF8($pValue = '')
655	{
656		// If there is no escape character in the string there is nothing to do
657		if (strpos($pValue, '') === false) {
658			return $pValue;
659		}
660
661		foreach (self::$_SYLKCharacters as $k => $v) {
662			$pValue = str_replace($k, $v, $pValue);
663		}
664
665		return $pValue;
666	}
667
668}