16 || ( c ==
'/' && subs.
Length() > 1 && subs.
CharAt(1) ==
'/' );
49 if( secIt->Name.Equals(name)) {
50 auto* section= &*secIt;
53 if( entryIt->second.SectionPointer == section ) {
66 for(
auto entryIt= section->
Entries.begin() ; entryIt != section->
Entries.end(); ++entryIt ) {
68 if( entryIt->Name.Equals(name)) {
69 auto* entry= &*entryIt;
81 Handle{section, &newEntry} );
91 return Handle{
nullptr,
nullptr};
105std::pair<IniFile::Section*, bool>
109 return std::make_pair( s,
false );
134 file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
140 if ( !file.is_open() || errno ) {
153 String4K actComments;
ALIB_DBG( actComments.DbgDisableBufferReplacementWarning(); )
156 String8 equalSignOrWhitespace(
'=');
169 bool writebackFlag =
false;
170 int qtyEntriesRead = 0;
172 bool fileHeaderRead =
false;
173 while( !reader.
IsEOF() ) {
174 reader.
Read(actLine); ++lineNo;
180 if ( !fileHeaderRead && lineTrimmed.
IsEmpty() ) {
181 fileHeaderRead=
true;
182 if (actComments.IsNotEmpty())
189 actComments._(actLine).NewLine();
201 fileHeaderRead=
true;
209 if( actSection->Comments.IsEmpty())
211 actSection->WriteBack= writebackFlag;
212 writebackFlag=
false;
226 actName << lineTrimmed;
229 actName << lineTrimmed.
Substring( 0, idx );
232 actRawValue.
_(lineTrimmed);
240 reader.
Read(actLine);
241 if ( reader.
IsEOF() ) {
247 actRawValue << (actLine);
248 lineTrimmed= actLine;
254 if( entry ==
nullptr) {
259 entry->RawValue.Allocate(
Allocator, actRawValue );
260 entry->WriteBack= writebackFlag;
261 if(entry->LineNo>= 0 && entry->FirstLineNo == -1 )
262 entry->FirstLineNo= entry->LineNo;
263 entry->LineNo= lineNo;
264 writebackFlag=
false;
272 while((parser= tknzr.
Next()).IsNotNull()) {
279 trimmedValue << parser;
281 entry->Value.Allocate(
Allocator, trimmedValue );
290 return qtyEntriesRead;
304 "Given Path is empty and no known filename from previous Read() operation available.")
309 file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
312 file.open( path.
Terminate(), std::ios::binary );
314 if ( !file.is_open() || errno ) {
333 if( section.Name.IsNotEmpty()) {
335 if(section.Comments.CharAtStart() !=
'\n' && section.Comments.CharAtStart() !=
'\r')
337 writer.
Write( section.Comments );
338 if(section.WriteBack) {
339 writer.
Write( writeBackAttribute );
347 for (
auto& entry : section.Entries )
348 maxVarLength= (std::max)( maxVarLength, entry.Name.Length() );
350 for (
auto& entry : section.Entries ) {
352 if( entry.Comments.IsNotEmpty()) {
353 if (entry.Comments.CharAtStart() !=
'\n' && entry.Comments.CharAtStart() !=
'\r')
355 writer.
Write( entry.Comments );
358 if(entry.WriteBack) {
359 writer.
Write( writeBackAttribute );
362 writer.
Write( entry.Name );
365 if( entry.NewValue.IsNull()) {
366 writer.
Write( entry.RawValue );
367 if(!entry.NewValue.EndsWith(
NEW_LINE))
376 writer.
Fill(
' ', maxVarLength - ( cntLine == 0 ? entry.Name.Length() - 1
384 writer.
Write(
"\\" );
386 writer.
Write( actual );
392 if( actual.
Length() > maxValLength )
393 maxValLength= actual.
Length() + 2;
394 writer.
Fill(
' ', maxValLength - actual.
Length() );
396 writer.
Write(
"\\" );
#define ALIB_CALLER_NULLED
#define ALIB_ASSERT_RESULT_GREATER_THAN(func, value)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Exception & Add(const lang::CallerInfo &ci, TEnum type, TArgs &&... args)
constexpr const TChar * Terminate() const
TAString & _(const TAppendable &src)
void DbgDisableBufferReplacementWarning()
TAString & TrimEnd(const TCString< TChar > &trimChars=CStringConstantsTraits< TChar >::DefaultWhitespaces())
constexpr integer Length() const
constexpr bool IsEmpty() const
TChar CharAtStart() const
constexpr bool IsNotNull() const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
TChar CharAt(integer idx) const
constexpr bool IsNotEmpty() const
integer IndexOfAny(const TString &needles, integer startIdx=0) const
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
bool Equals(const TString< TChar > &rhs) const
TSubstring & TrimStart(const TCString< TChar > &whiteSpaces=CStringConstantsTraits< TChar >::DefaultWhitespaces())
bool ConsumeCharFromEnd(TChar consumable)
integer ConsumeChars(integer regionLength, TSubstring *target=nullptr)
TSubstring & Trim(const TCString< TChar > &whiteSpaces=CStringConstantsTraits< TChar >::DefaultWhitespaces())
TString< TChar > ConsumeToken(TChar separator=',', lang::Inclusion includeSeparator=lang::Inclusion::Include)
TSubstring & TrimEnd(const TCString< TChar > &whiteSpaces=CStringConstantsTraits< TChar >::DefaultWhitespaces())
void Read(NAString &target)
void SetStream(::std::istream *is)
void Write(const NString &src, integer *printedWidth=nullptr)
void Fill(const TChar fillChar, integer count)
TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
void Reset()
Clears all data, resets the internal mono allocator.
Entry * DeleteEntry(Section *section, const String &name)
Section * CreateSection(const String &name)
Entry * CreateEntry(Section *section, const String &name)
void AddComments(String &dest, const String &comments, const String &prefix=A_CHAR("# "))
HashMap< MonoAllocator, EntryKey, Handle, EntryKey::Hash, EntryKey::EqualTo > entryTable
ListMA< integer > LinesWithReadErrors
bool startsWithCommentSymbol(String &subs)
Handle SearchEntry(const String §ion, const String &name)
std::pair< Section *, bool > SearchOrCreateSection(const String §ionName)
ListMA< Section > Sections
The list of sections.
PathString FileName
The file name.
IniFile()
Default constructor.
int Read(const CPathString &path)
Section * DeleteSection(const String &name)
void Write(const PathString &path=NULL_PATH)
MonoAllocator Allocator
A monotonic allocator used for allocating sections and entries.
Section * SearchSection(const String §ionName)
String FileComments
The file header which will be written out as comment lines with "# " prefixes.
Exception CreateExceptionFromSystemError(const CallerInfo &ci, std::error_code errorCode)
@ Include
Chooses inclusion.
Exceptions
Exception codes of namespace #"alib::variables;2".
@ ErrorWritingFile
An error occurred writing the file .
@ ErrorOpeningFile
File not found when reading.
strings::compatibility::std::IStreamReader IStreamReader
Type alias in namespace #"%alib".
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace #"%alib".
LocalString< 8 > String8
Type alias name for #"TLocalString;TLocalString<character,8>".
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
constexpr const String EMPTY_STRING
An empty string of the default character type.
lang::integer integer
Type alias in namespace #"%alib".
LocalString< 4096 > String4K
Type alias name for #"TLocalString;TLocalString<character,4096>".
strings::TString< character > String
Type alias in namespace #"%alib".
strings::TCString< PathCharType > CPathString
The string-type used with this ALib Module.
strings::TSubstring< character > Substring
Type alias in namespace #"%alib".
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class #"Basecamp".
exceptions::Exception Exception
Type alias in namespace #"%alib".
constexpr CString DEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
LocalString< 128 > String128
Type alias name for #"TLocalString;TLocalString<character,128>".
NLocalString< 256 > NString256
Type alias name for #"TLocalString;TLocalString<nchar,256>".
LocalString< 256 > String256
Type alias name for #"TLocalString;TLocalString<character,256>".
LocalString< 2048 > String2K
Type alias name for #"TLocalString;TLocalString<character,2048>".
strings::compatibility::std::OStreamWriter< TChar, TAllocator, TSynced, TTargetLF > OStreamWriter
Type alias in namespace #"%alib".
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
Hash functor for nodes hashed in field #"entryTable". Ignores letter case.
An entry in a #"IniFile::Section".
String Name
The entry's name.
String Comments
The entry's comments.
A pair of pointers to a section and an entry in the section.
Entry * EntryPointer
Pointer to the entry in the #"SectionPointer".
A section of the INI-file.
ListMA< Entry, Recycling::None > Entries
The list of variables of the section.
String Name
The name of the section.