#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/string_view.h>
#include <list>
/*}}}*/
using std::string;
+using APT::StringView;
class APT_HIDDEN pkgTagFilePrivate /*{{{*/
{
}
/*}}}*/
// TagSection::Exists - return True if a tag exists /*{{{*/
-bool pkgTagSection::Exists(const char* const Tag) const
+bool pkgTagSection::Exists(StringView Tag) const
{
unsigned int tmp;
return Find(Tag, tmp);
// TagSection::Find - Locate a tag /*{{{*/
// ---------------------------------------------------------------------
/* This searches the section for a tag that matches the given string. */
-bool pkgTagSection::Find(const char *Tag,unsigned int &Pos) const
+bool pkgTagSection::Find(StringView TagView,unsigned int &Pos) const
{
- size_t const Length = strlen(Tag);
+ const char * const Tag = TagView.data();
+ size_t const Length = TagView.length();
unsigned int Bucket = AlphaIndexes[AlphaHash(Tag, Length)];
if (Bucket == 0)
return false;
Pos = 0;
return false;
}
-bool pkgTagSection::Find(const char *Tag,const char *&Start,
+
+bool pkgTagSection::Find(StringView Tag,const char *&Start,
const char *&End) const
{
unsigned int Pos;
}
/*}}}*/
// TagSection::FindS - Find a string /*{{{*/
-string pkgTagSection::FindS(const char *Tag) const
+StringView pkgTagSection::Find(StringView Tag) const
{
const char *Start;
const char *End;
if (Find(Tag,Start,End) == false)
- return string();
- return string(Start,End);
+ return StringView();
+ return StringView(Start, End - Start);
}
/*}}}*/
// TagSection::FindRawS - Find a string /*{{{*/
-string pkgTagSection::FindRawS(const char *Tag) const
+StringView pkgTagSection::FindRaw(StringView Tag) const
{
unsigned int Pos;
if (Find(Tag, Pos) == false)
for (; isspace_ascii(End[-1]) != 0 && End > Start; --End);
- return std::string(Start, End - Start);
+ return StringView(Start, End - Start);
}
/*}}}*/
// TagSection::FindI - Find an integer /*{{{*/
// ---------------------------------------------------------------------
/* */
-signed int pkgTagSection::FindI(const char *Tag,signed long Default) const
+signed int pkgTagSection::FindI(StringView Tag,signed long Default) const
{
const char *Start;
const char *Stop;
// TagSection::FindULL - Find an unsigned long long integer /*{{{*/
// ---------------------------------------------------------------------
/* */
-unsigned long long pkgTagSection::FindULL(const char *Tag, unsigned long long const &Default) const
+unsigned long long pkgTagSection::FindULL(StringView Tag, unsigned long long const &Default) const
{
const char *Start;
const char *Stop;
// TagSection::FindB - Find boolean value /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool pkgTagSection::FindB(const char *Tag, bool const &Default) const
+bool pkgTagSection::FindB(StringView Tag, bool Default) const
{
const char *Start, *Stop;
if (Find(Tag, Start, Stop) == false)
// TagSection::FindFlag - Locate a yes/no type flag /*{{{*/
// ---------------------------------------------------------------------
/* The bits marked in Flag are masked on/off in Flags */
-bool pkgTagSection::FindFlag(const char * const Tag, uint8_t &Flags,
+bool pkgTagSection::FindFlag(StringView Tag, uint8_t &Flags,
uint8_t const Flag) const
{
const char *Start;
}
return true;
}
-bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags,
+bool pkgTagSection::FindFlag(StringView Tag,unsigned long &Flags,
unsigned long Flag) const
{
const char *Start;
else
return Tag(REWRITE, Name, Data);
}
-static bool WriteTag(FileFd &File, std::string Tag, std::string const &Value)
+static bool WriteTag(FileFd &File, std::string Tag, StringView Value)
{
if (Value.empty() || isspace_ascii(Value[0]) != 0)
Tag.append(":");
else
Tag.append(": ");
- Tag.append(Value);
+ Tag.append(Value.data(), Value.length());
Tag.append("\n");
return File.Write(Tag.c_str(), Tag.length());
}
}
else if(R->Action == pkgTagSection::Tag::RENAME && R->Data.length() == TagLen &&
strncasecmp(R->Data.c_str(), Tag, R->Data.length()) == 0)
- data = This->FindRawS(R->Name.c_str());
+ data = This->FindRaw(R->Name.c_str()).to_string();
else
continue;
if (Exists(Order[I]) == false)
continue;
- if (WriteTag(File, Order[I], FindRawS(Order[I])) == false)
+ if (WriteTag(File, Order[I], FindRaw(Order[I])) == false)
return false;
}
}
if (R != Rewrite.end())
continue;
- if (WriteTag(File, name, FindRawS(name.c_str())) == false)
+ if (WriteTag(File, name, FindRaw(name)) == false)
return false;
}
}
continue;
}
- if (WriteTag(File, name, ((R->Action == Tag::RENAME) ? FindRawS(R->Name.c_str()) : R->Data)) == false)
+ if (WriteTag(File, name, ((R->Action == Tag::RENAME) ? FindRaw(R->Name) : R->Data)) == false)
return false;
}
return true;
// See if it is in the fragment
unsigned Pos;
- if (Tags.Find(Order[I],Pos) == false)
+ if (Tags.Find(StringView(Order[I]),Pos) == false)
continue;
Visited[Pos] |= 1;