| javascript_core

# Class: Bs_CsvUtil Source Location: /core/util/Bs_CsvUtil.class.js.php
### Class Overview
csv util class. csv = comma separated value. #### Author(s): andrej arn <at blueshoes dot org> #### Version: 4.4.$Revision: 1.2 $ $Date: 2003/08/09 15:16:17 $ #### Copyright: blueshoes.org | ### Variables Bs_CsvUtil:: | ### Methods Bs_CsvUtil csvArrayToArray csvStringToArray
### Inherited Variables | ### Inherited Methods
### Class Details [line 34] csv util class. csv = comma separated value. this is a translation of the php class. features: supports any separator char sequence, default is semicolon ";" supports separator characters in the values. eg you use a ; as separator, your line may look like blah;hello world;"foo";"foo;bar";"this is a ""string""";got it?;foo as you can see, the values can be in "quotes". if your text uses quotes itself as in the "string" example, they are escaped in ms-style with 2 quotes. and by using quotes we can even have your separator inside the text (example "foo;bar"). line breaks. a csv line may spread over multiple lines using crlf in a field value. see the checkMultiline param and the _checkMultiline() method. missing: option to change quote char (") to something else example: $c =& new Bs_CsvUtil; dump($c->csvFileToArray('/some/path/file.csv')); dependencies: Bs_String.lib.js #### Tags:
since: | bs4.4
version: | 4.4.$Revision: 1.2 $ $Date: 2003/08/09 15:16:17 $
copyright: | blueshoes.org
author: | andrej arn <at blueshoes dot org>
[ Top ] ### Class Variables #### = separator.length [line 137]
Type: | mixed
[ Top ] ### Class Methods ### constructor Bs_CsvUtil [line 45]
`Bs_CsvUtil Bs_CsvUtil( )`
Constructor. not called yet. [ Top ] ### method csvArrayToArray [line 116]
`array csvArrayToArray( string {if(typeof(separator, array typeof(trim, string typeof(removeHeader, string typeof(removeEmptyLines, bool trim, bool 5)`
reads in a cvs array and returns it as a 2-dim vector. cvs = comma separated value. you can easily export that from an excel file for example. it looks like: headerCellOne;headerCellTwo;headerCellThree dataCellOne;dataCellTwo;dataCellThree apple;peach;banana;grapefruit linux;windows;mac 1;2;3 note I: all returned array elements are strings even if the values were numeric. note II: it may be that one array has another array-length than another. in the example above, the fruits have 4 elements while the others just have 3. this is not catched. ideally every sub-array would have 4 elements. this would have to be added when needed, maybe with another param in the function call. #### Tags:
return: | (2-dim vector. it may be an empty array if there is no data.)
see: | Bs_CsvUtil::csvStringToArray()
throws: | bool FALSE on any error.
#### Parameters:
bool | 5 | removeEmptyLines (default is FALSE. would remove empty lines, that is, lines where the cells are empty. white spaces count as empty aswell.)
string | {if(typeof(separator | fullPath (fullpath to the cvs file)
array | typeof(trim | array (hash or vector where the values are the csv lines)
string | typeof(removeHeader | separator (cell separator, default is ';')
string | typeof(removeEmptyLines | trim (if we should trim the cells, default is 'none', can also be 'left', 'right' or 'both'. 'none' kinda makes it faster, omits many function calls, remember that.)
bool | trim | removeHeader (default is FALSE. would remove the first line which usually is the title line.)
[ Top ] ### method csvStringToArray [line 59]
`array csvStringToArray( string string, string separator, bool trim, bool removeHeader, bool removeEmptyLines, mixed checkMultiline)`
takes a csv-string and returns it as a 2-dim vector. #### Tags:
see: | Bs_CsvUtil::csvArrayToArray()
#### Parameters:
string | string | string
string | separator | separator (default is ';'. set to 'auto' if you don't know, it will then be guessed. see this.guessSeparator().)
bool | trim | removeHeader (default is false, if the first line should be removed cause it's a header.)
bool | removeHeader | removeEmptyLines (if empty lines should be removed. default is false... you might want to change this. especially empty lines at the eof are annoying.)
bool | removeEmptyLines | checkMultiline (default is false, see _checkMultiline())
[ Top ] Documentation generated on Mon, 29 Dec 2003 22:18:17 +0100 by phpDocumentor 1.2.3