8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
62 || ( c ==
'/' && subs.
Length() > 1 && subs.
CharAt(1) ==
'/' );
100 if( secIt->Name.Equals(name))
102 auto* section= &*secIt;
106 if( entryIt->second.first == section )
123 for(
auto entryIt= section->
Entries.begin() ; entryIt != section->
Entries.end(); ++entryIt )
126 if( entryIt->Name.Equals(name))
128 auto* entry= &*entryIt;
142 std::make_pair(section, &newEntry) );
152 return std::pair<Section*, Entry*>(
nullptr,
nullptr);
168std::pair<IniFile::Section*, bool>
173 return std::make_pair( s,
false );
199 std::ifstream file( nPath );
201 if ( !file.is_open() )
206 if ( errNo ==
int(SystemErrors::enoent) )
216 throw std::runtime_error(
"ErrorOpeningFile");
225 String4K actComments;
ALIB_DBG( actComments.DbgDisableBufferReplacementWarning(); )
228 String8 equalSignOrWhitespace(
'=');
241 bool writebackFlag =
false;
242 int qtyEntriesRead = 0;
244 bool fileHeaderRead =
false;
245 while( !reader.
IsEOF() )
247 reader.
Read( actLine ); ++lineNo;
253 if ( !fileHeaderRead && lineTrimmed.
IsEmpty() )
255 fileHeaderRead=
true;
263 actComments._(actLine).NewLine();
277 fileHeaderRead=
true;
286 if( actSection->Comments.IsEmpty())
288 actSection->WriteBack= writebackFlag;
289 writebackFlag=
false;
303 actName << lineTrimmed;
308 actName << lineTrimmed.
Substring( 0, idx );
311 actRawValue.
_(lineTrimmed);
319 reader.
Read( actLine );
320 if ( reader.
IsEOF() )
327 actRawValue << (actLine);
328 lineTrimmed= actLine;
333 auto* entry=
SearchEntry( actSection->Name, actName ).second;
334 if( entry ==
nullptr)
342 "Variable \"{}\" was found twice in INI-file. First value will be discarded "
343 "on writing.",
String(actName) )
345 entry->Comments.Allocate(
Allocator, actComments );
346 entry->RawValue.Allocate(
Allocator, actRawValue );
347 entry->WriteBack= writebackFlag;
348 writebackFlag=
false;
356 while((parser= tknzr.
Next()).IsNotNull())
364 trimmedValue << parser;
366 entry->Value.Allocate(
Allocator, trimmedValue );
375 return qtyEntriesRead;
390 "Given Path is empty and no known filename from previous Read() operation available.")
393 std::ofstream outputFileStream( path.
Terminate(), std::ios::binary );
394 if ( !outputFileStream.is_open() )
402 throw std::runtime_error(
"ErrorWritingFile");
420 if( section.Name.IsNotEmpty())
423 if(section.Comments.CharAtStart() !=
'\n' && section.Comments.CharAtStart() !=
'\r')
425 writer.
Write( section.Comments );
426 if(section.WriteBack)
428 writer.
Write( writeBackAttribute );
436 for (
auto& entry : section.Entries )
437 maxVarLength= (std::max)( maxVarLength, entry.Name.Length() );
439 for (
auto& entry : section.Entries )
442 if( entry.Comments.IsNotEmpty())
444 if (entry.Comments.CharAtStart() !=
'\n' && entry.Comments.CharAtStart() !=
'\r')
446 writer.
Write( entry.Comments );
451 writer.
Write( writeBackAttribute );
454 writer.
Write( entry.Name );
457 if( entry.NewValue.IsNull())
459 writer.
Write( entry.RawValue );
460 if(!entry.NewValue.EndsWith(
NEW_LINE))
472 writer.
WriteChars(
' ', maxVarLength - ( cntLine == 0 ? entry.Name.Length() - 1
480 writer.
Write(
"\\" );
482 writer.
Write( actual );
489 if( actual.
Length() > maxValLength )
490 maxValLength= actual.
Length() + 2;
493 writer.
Write(
"\\" );
503 outputFileStream.close();
Exception & Add(const lang::CallerInfo &ci, TEnum type, TArgs &&... args)
constexpr const TChar * Terminate() const
TAString & _(const TAppendable &src)
TAString & TrimEnd(const TCString< TChar > &trimChars=CStringConstantsTraits< TChar >::DefaultWhitespaces())
constexpr integer Length() const
constexpr bool IsEmpty() const
TChar CharAtStart() const
constexpr bool IsNotNull() const
TChar CharAt(integer idx) const
constexpr bool IsNotEmpty() const
integer IndexOfAny(const TString &needles, integer startIdx=0) const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
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 SetStream(::std::istream *is)
void Read(NAString &target)
void SetStream(::std::ostream *os)
ALIB_DLL void WriteChars(const nchar fillChar, integer count)
ALIB_DLL void Write(const NString &src)
ALIB_DLL TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
ALIB_DLL void Reset()
Clears all data, resets the internal mono allocator.
ALIB_DLL Entry * DeleteEntry(Section *section, const String &name)
ALIB_DLL Section * CreateSection(const String &name)
ALIB_DLL void Write(const system::PathString &path=system::NULL_PATH)
ALIB_DLL Entry * CreateEntry(Section *section, const String &name)
ALIB_DLL void AddComments(String &dest, const String &comments, const String &prefix=A_CHAR("# "))
system::PathString FileName
The file name.
bool startsWithCommentSymbol(String &subs)
HashMap< MonoAllocator, EntryKey, std::pair< Section *, Entry * >, EntryKey::Hash, EntryKey::EqualTo > entryTable
List< MonoAllocator, integer > LinesWithReadErrors
ALIB_DLL std::pair< Section *, bool > SearchOrCreateSection(const String §ionName)
List< MonoAllocator, Section > Sections
The list of sections.
ALIB_DLL std::pair< Section *, Entry * > SearchEntry(const String §ion, const String &name)
ALIB_DLL integer Read(const system::CPathString &path)
ALIB_DLL IniFile()
Default constructor.
ALIB_DLL Section * DeleteSection(const String &name)
MonoAllocator Allocator
A monotonic allocator used for allocating sections and entries.
ALIB_DLL Section * SearchSection(const String §ionName)
String FileComments
The file header which will be written out as a comment lines with "# " prefixes.
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_CALLER_NULLED
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_RESULT_GREATER_THAN(func, value)
#define ALIB_ASSERT_ERROR(cond, domain,...)
@ Include
Chooses inclusion.
strings::TCString< PathCharType > CPathString
The string-type used with this ALib Module.
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
Exception CreateSystemException(const CallerInfo &ci, int errNo)
@ ErrorWritingFile
An error occurred writing the file .
@ ErrorOpeningFile
File not found when reading.
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
LocalString< 4096 > String4K
Type alias name for TLocalString<character,4096>.
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class Basecamp.
LocalString< 128 > String128
Type alias name for TLocalString<character,128>.
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< 8 > String8
Type alias name for TLocalString<character,8>.
constexpr CString DEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
exceptions::Exception Exception
Type alias in namespace alib.
strings::compatibility::std::StringWriter StringWriter
Type alias in namespace alib.
strings::compatibility::std::StringReader StringReader
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
LocalString< 2048 > String2K
Type alias name for TLocalString<character,2048>.
strings::TSubstring< character > Substring
Type alias in namespace alib.
Hash functor for nodes hashed in field entryTable. Ignores letter case.
String Name
The entry's name.
A section of the INI-file.
List< MonoAllocator, Entry, Recycling::None > Entries
The list of variables of the section.
String Name
The name of the section.