 |
SAGA API
v9.7
|
Go to the documentation of this file.
119 case TABLE_FILETYPE_Text:
default:
if( !_Load_Text (FileName,
true , Separator) )
return(
false );
break;
167 if( Separator ==
'\0' )
175 bool bResult =
false;
232 for(
size_t i=0; i<s.
Length(); i++)
236 if( c == Separator || (c !=
' ' && c !=
'\t' && c !=
'\n' && c !=
'\v' && c !=
'\f' && c !=
'\r') )
251 size_t CSG_Table::_Load_Text_EndQuote(
const CSG_String &s,
const SG_Char Separator)
253 if( s.
Length() > 1 && s[0] ==
'\"' )
255 bool bInQuotes =
true;
257 for(
size_t i=1; i<s.
Length(); i++)
266 else if( s[i] ==
'\"' )
270 else if( s[i] == Separator )
276 if( s[s.
Length() - 1] ==
'\"' )
286 bool CSG_Table::_Load_Text(
const CSG_String &FileName,
bool bHeadline,
const SG_Char _Separator)
310 if( Line[0] == 65279 )
317 while( Line.
is_Empty() || (bCSV && Line[0] ==
'#') )
326 SG_Char Separator = _Separator;
328 if( Separator ==
'\0' )
332 Separator = Line.
Find(
';') >= 0 ?
';' :
',';
340 bool bComma2Point = bCSV && Separator ==
';';
345 _Load_Text_Trim(Line, Separator);
351 if( Line[0] ==
'\"' )
361 Line = Line.
AfterFirst(Separator); _Load_Text_Trim(Line, Separator);
363 if( !bHeadline || Value.
Length() == 0 )
386 if( Line.
is_Empty() || (bCSV && Line[0] ==
'#') )
393 _Load_Text_Trim(Line, Separator);
397 size_t Position = _Load_Text_EndQuote(Line, Separator);
CSG_String Value;
401 if( Position - 2 > 0 )
403 Value = Line.
Mid(1, Position - 2);
424 Line = Line.
AfterFirst(Separator); _Load_Text_Trim(Line, Separator);
429 if( Value[0] ==
'0' && Value[1] !=
'.' )
435 size_t pos;
double number = std::stod(Value.
to_StdString(), &pos);
437 if( pos < Value.
Length() )
470 if( *Table[i].asString(Field) )
472 Record.
Set_Value(Field, Table[i].asString(Field));
552 bool CSG_Table::_Load_DBase(
const CSG_String &FileName)
556 return( dbf.Open_Read(FileName,
this) );
591 for(
int Field=0; Field<Values.
Get_Count(); Field++)
607 if( Value.
Length() >= 2 && Value[0] ==
'\"' && Value[Value.
Length() - 1] ==
'\"' )
616 if( Value[0] ==
'0' && Value[1] !=
'.' )
622 size_t pos;
double number = std::stod(Value.
to_StdString(), &pos);
624 if( pos < Value.
Length() )
664 for(
sLong i=0; i<n; i++)
694 for(
int Field=0; Field<
m_nFields; Field++)
701 for(
int Field=0; Field<
m_nFields; Field++)
713 if( Stream.
Read_Line(sLine) &&
SG_SSCANF(sLine,
SG_T(
"%d %lld"), &nFields, &nRecords) == 2 && nFields > 0 )
717 for(
int Field=0; Field<nFields; Field++)
725 for(
sLong i=0; i<nRecords; i++)
731 for(
int Field=0; Field<
m_nFields; Field++)
CSG_String BeforeFirst(char Character) const
int Printf(const char *Format,...)
bool Seek_Start(void) const
void Set_File_Name(const CSG_String &FileName)
size_t Length(void) const
CSG_String & Remove(size_t pos)
CSG_String Mid(size_t first, size_t count=0) const
@ SG_UI_MSG_STYLE_SUCCESS
virtual CSG_Table_Record * Get_Record(sLong Index) const
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &FileName, const CSG_String &Extension)
bool Save_MetaData(const CSG_String &FileName)
virtual CSG_Table_Record * Get_Selection(sLong Index=0) const
virtual bool Destroy(void)
virtual bool On_Reload(void)
bool Open_Write(const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Save=true)
int Get_Field_Count(void) const
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
@ TABLE_FILETYPE_Undefined
CSG_String to_Text(bool Selection=false) const
virtual bool On_Delete(void)
void Set_Update_Flag(bool bOn=true)
bool is_NoData(int Field) const
virtual void Set_Modified(bool bModified=true)
@ SG_UI_MSG_STYLE_FAILURE
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
const SG_Char * asString(int Field, int Decimals=-99) const
const SG_Char * Get_Field_Name(int iField) const
std::string to_StdString(void) const
@ SG_FILE_ENCODING_UNDEFINED
bool Set_File_Encoding(int Encoding)
sLong Get_Selection_Count(void) const
bool Serialize(CSG_File &Stream, bool bSave)
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
sLong Get_Count(void) const
SAGA_API_DLL_EXPORT CSG_Strings SG_String_Tokenize(const CSG_String &String, const CSG_String &Delimiters=SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode=SG_TOKEN_DEFAULT)
void Set_File_Type(int Type)
@ TABLE_FILETYPE_Text_NoHeadLine
const SG_Char * Get_File_Name(bool bNative=true) const
CSG_Table_Record * Get_Record_byIndex(sLong Index) const
size_t Replace(const CSG_String &Old, const CSG_String &New, bool bReplaceAll=true)
void Set_Name(const CSG_String &Name)
static CSG_String Format(const char *Format,...)
int Find(char Character, bool fromEnd=false) const
bool Set_Field_Name(int iField, const SG_Char *Name)
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
const char gSG_Data_Type_Identifier[][32]
bool _Save_DBase(const CSG_String &File)
CSG_String AfterFirst(char Character) const
bool Load(const CSG_String &File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED)
CSG_MetaData & Get_MetaData_DB(void) const
int Printf(const char *Format,...)
bool is_Empty(void) const
bool SG_UI_Process_Set_Progress(int Position, int Range)
bool Set_Value(int Field, const CSG_String &Value)
bool Read_Line(CSG_String &Line) const
bool from_Text(const CSG_String &Text)
bool Load_MetaData(const CSG_String &FileName)
virtual bool Save(const CSG_String &File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED)
const SG_Char * c_str(void) const
bool SG_UI_Process_Set_Ready(void)
int Get_Count(void) const
TSG_Data_Type Get_Field_Type(int iField) const
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
virtual bool Set_Field_Type(int iField, TSG_Data_Type Type)
bool Set_NoData(int Field)
bool _Save_Text(const CSG_String &File, bool bHeadline, const SG_Char Separator)
CSG_String Right(size_t count) const
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)