File: Added delimiter to get_csv_line

This commit is contained in:
tmt 2016-01-28 15:58:39 +01:00
parent 0c7e7e2c28
commit 2447c3171f
4 changed files with 9 additions and 7 deletions

View File

@ -1313,9 +1313,9 @@ String _File::get_line() const{
} }
Vector<String> _File::get_csv_line() const { Vector<String> _File::get_csv_line(String delim) const {
ERR_FAIL_COND_V(!f,Vector<String>()); ERR_FAIL_COND_V(!f,Vector<String>());
return f->get_csv_line(); return f->get_csv_line(delim);
} }
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
@ -1498,7 +1498,7 @@ void _File::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap); ObjectTypeDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
ObjectTypeDB::bind_method(_MD("get_error:Error"),&_File::get_error); ObjectTypeDB::bind_method(_MD("get_error:Error"),&_File::get_error);
ObjectTypeDB::bind_method(_MD("get_var"),&_File::get_var); ObjectTypeDB::bind_method(_MD("get_var"),&_File::get_var);
ObjectTypeDB::bind_method(_MD("get_csv_line"),&_File::get_csv_line); ObjectTypeDB::bind_method(_MD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
ObjectTypeDB::bind_method(_MD("store_8","value"),&_File::store_8); ObjectTypeDB::bind_method(_MD("store_8","value"),&_File::store_8);
ObjectTypeDB::bind_method(_MD("store_16","value"),&_File::store_16); ObjectTypeDB::bind_method(_MD("store_16","value"),&_File::store_16);

View File

@ -390,7 +390,7 @@ public:
virtual void store_pascal_string(const String& p_string); virtual void store_pascal_string(const String& p_string);
virtual String get_pascal_string(); virtual String get_pascal_string();
Vector<String> get_csv_line() const; Vector<String> get_csv_line(String delim=",") const;
void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes

View File

@ -277,7 +277,9 @@ String FileAccess::get_line() const {
return String::utf8(line.get_data()); return String::utf8(line.get_data());
} }
Vector<String> FileAccess::get_csv_line() const { Vector<String> FileAccess::get_csv_line(String delim) const {
ERR_FAIL_COND_V(delim.length()!=1,Vector<String>());
String l; String l;
int qc=0; int qc=0;
@ -303,7 +305,7 @@ Vector<String> FileAccess::get_csv_line() const {
CharType s[2]={0,0}; CharType s[2]={0,0};
if (!in_quote && c==',') { if (!in_quote && c==delim[0]) {
strings.push_back(current); strings.push_back(current);
current=String(); current=String();
} else if (c=='"') { } else if (c=='"') {

View File

@ -102,7 +102,7 @@ public:
virtual int get_buffer(uint8_t *p_dst,int p_length) const; ///< get an array of bytes virtual int get_buffer(uint8_t *p_dst,int p_length) const; ///< get an array of bytes
virtual String get_line() const; virtual String get_line() const;
virtual Vector<String> get_csv_line() const; virtual Vector<String> get_csv_line(String delim=",") const;
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
* It's not about the current CPU type but file formats. * It's not about the current CPU type but file formats.