From 734f3daf66a61afa84067682754515f524b3a84c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 24 Feb 2010 09:18:51 +0000 Subject: [PATCH] I hate std::string: the concept is great, the implementation is shit. A vindication.diff git-svn-id: http://svn.telesphoreo.org/trunk@703 514c082c-b64e-11dc-b46d-3d985efe055d --- apt-pkg/contrib/md5.cc | 11 ++++++ apt-pkg/contrib/md5.h | 4 ++ apt-pkg/contrib/strutl.cc | 7 +++- apt-pkg/contrib/strutl.h | 4 ++ apt-pkg/deb/deblistparser.cc | 71 ++++++++++++++++++++++++----------- apt-pkg/deb/deblistparser.h | 17 +++++++++ apt-pkg/makefile | 2 +- apt-pkg/pkgcache.cc | 13 +++++++ apt-pkg/pkgcache.h | 6 ++- apt-pkg/pkgcachegen.cc | 73 ++++++++++++++++++++++++++++-------- apt-pkg/pkgcachegen.h | 8 ++++ apt-pkg/srkstring.h | 64 +++++++++++++++++++++++++++++++ apt-pkg/version.h | 2 +- 13 files changed, 241 insertions(+), 41 deletions(-) create mode 100644 apt-pkg/srkstring.h diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc index c0fa849..6c91067 100644 --- a/apt-pkg/contrib/md5.cc +++ b/apt-pkg/contrib/md5.cc @@ -173,6 +173,12 @@ MD5SumValue::MD5SumValue(string Str) memset(Sum,0,sizeof(Sum)); Set(Str); } + +MD5SumValue::MD5SumValue(const srkString &Str) +{ + memset(Sum, 0, sizeof(Sum)); + Set(Str); +} /*}}}*/ // MD5SumValue::MD5SumValue - Default constructor /*{{{*/ // --------------------------------------------------------------------- @@ -186,6 +192,11 @@ MD5SumValue::MD5SumValue() // --------------------------------------------------------------------- /* Converts the hex string into a set of chars */ bool MD5SumValue::Set(string Str) +{ + return Hex2Num(Str,Sum,sizeof(Sum)); +} + +bool MD5SumValue::Set(const srkString &Str) { return Hex2Num(Str,Sum,sizeof(Sum)); } diff --git a/apt-pkg/contrib/md5.h b/apt-pkg/contrib/md5.h index 96c8975..afa448a 100644 --- a/apt-pkg/contrib/md5.h +++ b/apt-pkg/contrib/md5.h @@ -29,6 +29,8 @@ #include #include +#include + using std::string; using std::min; @@ -48,10 +50,12 @@ class MD5SumValue {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];}; inline operator string() const {return Value();}; bool Set(string Str); + bool Set(const srkString &Str); inline void Set(unsigned char S[16]) {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];}; MD5SumValue(string Str); + MD5SumValue(const srkString &Str); MD5SumValue(); }; diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 2913fbf..4e5ed8e 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -942,13 +942,18 @@ static int HexDigit(int c) // --------------------------------------------------------------------- /* The length of the buffer must be exactly 1/2 the length of the string. */ bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length) +{ + return Hex2Num(srkString(Str), Num, Length); +} + +bool Hex2Num(const srkString &Str,unsigned char *Num,unsigned int Length) { if (Str.length() != Length*2) return false; // Convert each digit. We store it in the same order as the string int J = 0; - for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2) + for (srkString::const_iterator I = Str.begin(); I != Str.end();J++, I += 2) { if (isxdigit(*I) == 0 || isxdigit(I[1]) == 0) return false; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 2b2e147..addc1f4 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -25,6 +25,8 @@ #include #include +#include + using std::string; using std::vector; using std::ostream; @@ -57,6 +59,7 @@ int StringToBool(const string &Text,int Default = -1); bool ReadMessages(int Fd, vector &List); bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0); bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length); +bool Hex2Num(const srkString &Str,unsigned char *Num,unsigned int Length); bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); void ioprintf(ostream &out,const char *format,...) APT_FORMAT2; @@ -66,6 +69,7 @@ bool CheckDomainList(const string &Host, const string &List); int tolower_ascii(int c); #define APT_MKSTRCMP(name,func) \ +inline int name(const srkString &A,const char *B) {return func(A.Start,A.Start+A.Size,B,B+strlen(B));}; \ inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \ inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \ inline int name(const string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));}; \ diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index de565d0..964e4a4 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -106,7 +106,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver) const char *Stop; if (Section.Find("Priority",Start,Stop) == true) { - if (GrabWord(string(Start,Stop-Start),PrioList,Ver->Priority) == false) + if (GrabWord(srkString(Start,Stop-Start),PrioList,Ver->Priority) == false) Ver->Priority = pkgCache::State::Extra; } @@ -144,10 +144,19 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver) only describe package properties */ string debListParser::Description() { - if (DescriptionLanguage().empty()) - return Section.FindS("Description"); - else - return Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()); + srkString description; + Description(description); + return description; +} + +void debListParser::Description(srkString &Str) { + const char *Start, *Stop; + if (!Section.Find("Description", Start, Stop)) + if (!Section.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(), Start, Stop)) { + Start = NULL; + Stop = NULL; + } + Str.assign(Start, Stop); } /*}}}*/ // ListParser::DescriptionLanguage - Return the description lang string /*{{{*/ @@ -157,7 +166,8 @@ string debListParser::Description() assumed to describe original description. */ string debListParser::DescriptionLanguage() { - return Section.FindS("Description").empty() ? pkgIndexFile::LanguageCode() : ""; + const char *Start, *Stop; + return Section.Find("Description", Start, Stop) ? std::string() : pkgIndexFile::LanguageCode(); } /*}}}*/ // ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/ @@ -168,15 +178,18 @@ string debListParser::DescriptionLanguage() */ MD5SumValue debListParser::Description_md5() { - string value = Section.FindS("Description-md5"); - - if (value.empty()) + const char *Start; + const char *Stop; + if (!Section.Find("Description-md5", Start, Stop)) { MD5Summation md5; - md5.Add((Description() + "\n").c_str()); + srkString description; + Description(description); + md5.Add((const unsigned char *) description.Start, description.Size); + md5.Add("\n"); return md5.Result(); } else - return MD5SumValue(value); + return MD5SumValue(srkString(Start, Stop)); } /*}}}*/ // ListParser::UsePackage - Update a package structure /*{{{*/ @@ -286,7 +299,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg, {"deinstall",pkgCache::State::DeInstall}, {"purge",pkgCache::State::Purge}, {}}; - if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false) + if (GrabWord(srkString(Start,I-Start),WantList,Pkg->SelectedState) == false) return _error->Error("Malformed 1st word in the Status line"); // Isloate the next word @@ -302,7 +315,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg, {"hold",pkgCache::State::HoldInst}, {"hold-reinstreq",pkgCache::State::HoldReInstReq}, {}}; - if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false) + if (GrabWord(srkString(Start,I-Start),FlagList,Pkg->InstState) == false) return _error->Error("Malformed 2nd word in the Status line"); // Isloate the last word @@ -324,7 +337,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg, {"post-inst-failed",pkgCache::State::HalfConfigured}, {"removal-failed",pkgCache::State::HalfInstalled}, {}}; - if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false) + if (GrabWord(srkString(Start,I-Start),StatusList,Pkg->CurrentState) == false) return _error->Error("Malformed 3rd word in the Status line"); /* A Status line marks the package as indicating the current @@ -409,6 +422,17 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op) const char *debListParser::ParseDepends(const char *Start,const char *Stop, string &Package,string &Ver, unsigned int &Op, bool ParseArchFlags) +{ + srkString cPackage, cVer; + const char *Value = ParseDepends(Start, Stop, cPackage, cVer, Op, ParseArchFlags); + Package = cPackage; + Ver = cVer; + return Value; +} + +const char *debListParser::ParseDepends(const char *Start,const char *Stop, + srkString &Package,srkString &Ver, + unsigned int &Op, bool ParseArchFlags) { // Strip off leading space for (;Start != Stop && isspace(*Start) != 0; Start++); @@ -509,7 +533,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, Found = !Found; if (Found == false) - Package = ""; /* not for this arch */ + Package.clear(); /* not for this arch */ } // Skip whitespace @@ -541,8 +565,8 @@ bool debListParser::ParseDepends(pkgCache::VerIterator Ver, if (Section.Find(Tag,Start,Stop) == false) return true; - string Package; - string Version; + srkString Package; + srkString Version; unsigned int Op; while (1) @@ -569,8 +593,8 @@ bool debListParser::ParseProvides(pkgCache::VerIterator Ver) if (Section.Find("Provides",Start,Stop) == false) return true; - string Package; - string Version; + srkString Package; + srkString Version; unsigned int Op; while (1) @@ -579,7 +603,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator Ver) if (Start == 0) return _error->Error("Problem parsing Provides line"); if (Op != pkgCache::Dep::NoOp) { - _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str()); + _error->Warning("Ignoring Provides line with DepCompareOp for package %s", std::string(Package).c_str()); } else { if (NewProvides(Ver,Package,Version) == false) return false; @@ -636,10 +660,15 @@ bool debListParser::ParseTag(pkgCache::PkgIterator Pkg) // --------------------------------------------------------------------- /* Looks for a word in a list of words - for ParseStatus */ bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out) +{ + return GrabWord(srkString(Word), List, Out); +} + +bool debListParser::GrabWord(const srkString &Word,WordList *List,unsigned char &Out) { for (unsigned int C = 0; List[C].Str != 0; C++) { - if (strcasecmp(Word.c_str(),List[C].Str) == 0) + if (strncasecmp(Word.Start,List[C].Str,Word.Size) == 0) { Out = List[C].Val; return true; diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 287d3e9..bd97f8b 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -41,9 +41,22 @@ class debListParser : public pkgCacheGenerator::ListParser bool ParseProvides(pkgCache::VerIterator Ver); bool ParseTag(pkgCache::PkgIterator Pkg); static bool GrabWord(string Word,WordList *List,unsigned char &Out); + static bool GrabWord(const srkString &Word,WordList *List,unsigned char &Out); public: + srkString Find(const char *Tag) { + srkString S; + const char *Stop; + if (Section.Find(Tag, S.Start, Stop)) + S.Size = Stop - S.Start; + else { + S.Start = NULL; + S.Size = 0; + } + return S; + } + static unsigned char GetPrio(string Str); // These all operate against the current section @@ -51,6 +64,7 @@ class debListParser : public pkgCacheGenerator::ListParser virtual string Version(); virtual bool NewVersion(pkgCache::VerIterator Ver); virtual string Description(); + void Description(srkString &Str); virtual string DescriptionLanguage(); virtual MD5SumValue Description_md5(); virtual unsigned short VersionHash(); @@ -67,6 +81,9 @@ class debListParser : public pkgCacheGenerator::ListParser static const char *ParseDepends(const char *Start,const char *Stop, string &Package,string &Ver,unsigned int &Op, bool ParseArchFlags = false); + static const char *ParseDepends(const char *Start,const char *Stop, + srkString &Package,srkString &Ver,unsigned int &Op, + bool ParseArchFlags = false); static const char *ConvertRelation(const char *I,unsigned int &Op); debListParser(FileFd *File); diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 85b4f2e..0b86ec9 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -42,7 +42,7 @@ HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \ acquire.h acquire-worker.h acquire-item.h acquire-method.h \ clean.h srcrecords.h cachefile.h versionmatch.h policy.h \ pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \ - vendorlist.h cdrom.h indexcopy.h aptconfiguration.h + vendorlist.h cdrom.h indexcopy.h aptconfiguration.h srkstring.h # Source code for the debian specific components # In theory the deb headers do not need to be exported.. diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index fd6bbd3..092ac88 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -176,11 +176,24 @@ unsigned long pkgCache::sHash(const char *Str) const return Hash % _count(HeaderP->HashTable); } +unsigned long pkgCache::sHash(const srkString &Str) const +{ + unsigned long Hash = 0; + for (const char *I = Str.Start, *E = I + Str.Size; I != E; I++) + Hash = 5*Hash + tolower_ascii(*I); + return Hash % _count(HeaderP->HashTable); +} + /*}}}*/ // Cache::FindPkg - Locate a package by name /*{{{*/ // --------------------------------------------------------------------- /* Returns 0 on error, pointer to the package otherwise */ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) +{ + return FindPkg(srkString(Name)); +} + +pkgCache::PkgIterator pkgCache::FindPkg(const srkString &Name) { // Look at the hash bucket Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)]; diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 3b4ff35..fc492e2 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -23,9 +23,10 @@ #include #include #include +#include using std::string; - + class pkgVersioningSystem; class pkgCache /*{{{*/ { @@ -102,6 +103,7 @@ class pkgCache /*{{{*/ unsigned long sHash(const string &S) const; unsigned long sHash(const char *S) const; + unsigned long sHash(const srkString &S) const; public: @@ -127,12 +129,14 @@ class pkgCache /*{{{*/ // String hashing function (512 range) inline unsigned long Hash(const string &S) const {return sHash(S);}; inline unsigned long Hash(const char *S) const {return sHash(S);}; + inline unsigned long Hash(const srkString &S) const {return sHash(S);}; // Usefull transformation things const char *Priority(unsigned char Priority); // Accessors PkgIterator FindPkg(const string &Name); + PkgIterator FindPkg(const srkString &Name); Header &Head() {return *HeaderP;}; inline PkgIterator PkgBegin(); inline PkgIterator PkgEnd(); diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 4dfb8f5..48a7976 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -33,6 +33,8 @@ #include #include #include + +#include /*}}}*/ typedef vector::iterator FileIterator; @@ -103,26 +105,37 @@ bool pkgCacheGenerator::MergeList(ListParser &List, pkgCache::VerIterator *OutVer) { List.Owner = this; + debListParser *debian(dynamic_cast(&List)); unsigned int Counter = 0; while (List.Step() == true) { // Get a pointer to the package structure - string PackageName = List.Package(); + srkString PackageName; + if (debian != NULL) + PackageName = debian->Find("Package"); + else + PackageName = List.Package(); if (PackageName.empty() == true) return false; pkgCache::PkgIterator Pkg; if (NewPackage(Pkg,PackageName) == false) - return _error->Error(_("Error occurred while processing %s (NewPackage)"),PackageName.c_str()); + return _error->Error(_("Error occurred while processing %s (NewPackage)"),std::string(PackageName).c_str()); Counter++; if (Counter % 100 == 0 && Progress != 0) Progress->Progress(List.Offset()); + string language(List.DescriptionLanguage()); + /* Get a pointer to the version structure. We know the list is sorted so we use that fact in the search. Insertion of new versions is done with correct sorting */ - string Version = List.Version(); + srkString Version; + if (debian != NULL) + Version = debian->Find("Version"); + else + Version = List.Version(); if (Version.empty() == true) { // we first process the package, then the descriptions @@ -130,7 +143,7 @@ bool pkgCacheGenerator::MergeList(ListParser &List, // of MMap space) if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false) return _error->Error(_("Error occurred while processing %s (UsePackage1)"), - PackageName.c_str()); + std::string(PackageName).c_str()); // Find the right version to write the description MD5SumValue CurMd5 = List.Description_md5(); @@ -147,7 +160,7 @@ bool pkgCacheGenerator::MergeList(ListParser &List, // md5 && language for ( ; Desc.end() == false; Desc++) if (MD5SumValue(Desc.md5()) == CurMd5 && - Desc.LanguageCode() == List.DescriptionLanguage()) + Desc.LanguageCode() == language) duplicate=true; if(duplicate) continue; @@ -159,11 +172,11 @@ bool pkgCacheGenerator::MergeList(ListParser &List, if (MD5SumValue(Desc.md5()) == CurMd5) { // Add new description - *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), CurMd5, *LastDesc); + *LastDesc = NewDescription(Desc, language, CurMd5, *LastDesc); Desc->ParentPkg = Pkg.Index(); if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false) - return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),PackageName.c_str()); + return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),std::string(PackageName).c_str()); break; } } @@ -189,11 +202,11 @@ bool pkgCacheGenerator::MergeList(ListParser &List, { if (List.UsePackage(Pkg,Ver) == false) return _error->Error(_("Error occurred while processing %s (UsePackage2)"), - PackageName.c_str()); + std::string(PackageName).c_str()); if (NewFileVer(Ver,List) == false) return _error->Error(_("Error occurred while processing %s (NewFileVer1)"), - PackageName.c_str()); + std::string(PackageName).c_str()); // Read only a single record and return if (OutVer != 0) @@ -224,15 +237,15 @@ bool pkgCacheGenerator::MergeList(ListParser &List, if ((*LastVer == 0 && _error->PendingError()) || List.NewVersion(Ver) == false) return _error->Error(_("Error occurred while processing %s (NewVersion1)"), - PackageName.c_str()); + std::string(PackageName).c_str()); if (List.UsePackage(Pkg,Ver) == false) return _error->Error(_("Error occurred while processing %s (UsePackage3)"), - PackageName.c_str()); + std::string(PackageName).c_str()); if (NewFileVer(Ver,List) == false) return _error->Error(_("Error occurred while processing %s (NewVersion2)"), - PackageName.c_str()); + std::string(PackageName).c_str()); // Read only a single record and return if (OutVer != 0) @@ -251,11 +264,11 @@ bool pkgCacheGenerator::MergeList(ListParser &List, for (; Desc.end() == false; LastDesc = &Desc->NextDesc, Desc++); // Add new description - *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), List.Description_md5(), *LastDesc); + *LastDesc = NewDescription(Desc, language, List.Description_md5(), *LastDesc); Desc->ParentPkg = Pkg.Index(); if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false) - return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),PackageName.c_str()); + return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),std::string(PackageName).c_str()); } FoundFileDeps |= List.HasFileDeps(); @@ -327,6 +340,11 @@ bool pkgCacheGenerator::MergeFileProvides(ListParser &List) // --------------------------------------------------------------------- /* This creates a new package structure and adds it to the hash table */ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name) +{ + return NewPackage(Pkg, srkString(Name)); +} + +bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const srkString &Name) { Pkg = Cache.FindPkg(Name); if (Pkg.end() == false) @@ -345,7 +363,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name Cache.HeaderP->HashTable[Hash] = Package; // Set the name and the ID - Pkg->Name = Map.WriteString(Name); + Pkg->Name = Map.WriteString(Name.Start,Name.Size); if (Pkg->Name == 0) return false; Pkg->ID = Cache.HeaderP->PackageCount++; @@ -392,6 +410,13 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver, unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, const string &VerStr, unsigned long Next) +{ + return NewVersion(Ver, srkString(VerStr), Next); +} + +unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, + const srkString &VerStr, + unsigned long Next) { // Get a structure unsigned long Version = Map.Allocate(sizeof(pkgCache::Version)); @@ -402,7 +427,7 @@ unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version); Ver->NextVer = Next; Ver->ID = Cache.HeaderP->VersionCount++; - Ver->VerStr = Map.WriteString(VerStr); + Ver->VerStr = Map.WriteString(VerStr.Start, VerStr.Size); if (Ver->VerStr == 0) return 0; @@ -477,6 +502,15 @@ bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver, const string &Version, unsigned int Op, unsigned int Type) +{ + return NewDepends(Ver, srkString(PackageName), srkString(Version), Op, Type); +} + +bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver, + const srkString &PackageName, + const srkString &Version, + unsigned int Op, + unsigned int Type) { pkgCache &Cache = Owner->Cache; @@ -540,6 +574,13 @@ bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver, bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver, const string &PackageName, const string &Version) +{ + return NewProvides(Ver, srkString(PackageName), srkString(Version)); +} + +bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver, + const srkString &PackageName, + const srkString &Version) { pkgCache &Cache = Owner->Cache; diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 2cfc417..306b117 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -52,9 +52,11 @@ class pkgCacheGenerator /*{{{*/ bool FoundFileDeps; bool NewPackage(pkgCache::PkgIterator &Pkg,const string &PkgName); + bool NewPackage(pkgCache::PkgIterator &Pkg,const srkString &PkgName); bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next); + unsigned long NewVersion(pkgCache::VerIterator &Ver,const srkString &VerStr,unsigned long Next); map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); public: @@ -96,11 +98,17 @@ class pkgCacheGenerator::ListParser inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; inline unsigned long WriteString(const string &S) {return Owner->Map.WriteString(S);}; inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);}; + inline unsigned long WriteString(const srkString &S) {return Owner->Map.WriteString(S.Start,S.Size);}; bool NewDepends(pkgCache::VerIterator Ver,const string &Package, const string &Version,unsigned int Op, unsigned int Type); + bool NewDepends(pkgCache::VerIterator Ver,const srkString &Package, + const srkString &Version,unsigned int Op, + unsigned int Type); bool NewProvides(pkgCache::VerIterator Ver,const string &Package, const string &Version); + bool NewProvides(pkgCache::VerIterator Ver,const srkString &Package, + const srkString &Version); bool NewTag(pkgCache::PkgIterator Pkg,const char *NameStart,unsigned int NameSize); public: diff --git a/apt-pkg/srkstring.h b/apt-pkg/srkstring.h new file mode 100644 index 0000000..a8fa123 --- /dev/null +++ b/apt-pkg/srkstring.h @@ -0,0 +1,64 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $ +/* ###################################################################### + + Cache - Structure definitions for the cache file + + Please see doc/apt-pkg/cache.sgml for a more detailed description of + this format. Also be sure to keep that file up-to-date!! + + Clients should always use the CacheIterators classes for access to the + cache. They provide a simple STL-like method for traversing the links + of the datastructure. + + See pkgcachegen.h for information about generating cache structures. + + ##################################################################### */ + /*}}}*/ +#ifndef PKGLIB_PKGSTRING_H +#define PKGLIB_PKGSTRING_H + +#include + +class srkString +{ + public: + const char *Start; + size_t Size; + + srkString() : Start(NULL), Size(0) {} + + srkString(const char *Start, size_t Size) : Start(Start), Size(Size) {} + srkString(const char *Start, const char *Stop) : Start(Start), Size(Stop - Start) {} + srkString(const std::string &string) : Start(string.c_str()), Size(string.size()) {} + + bool empty() const { return Size == 0; } + void clear() { Start = NULL; Size = 0; } + + void assign(const char *nStart, const char *nStop) { Start = nStart; Size = nStop - nStart; } + void assign(const char *nStart, size_t nSize) { Start = nStart; Size = nSize; } + + size_t length() const { return Size; } + size_t size() const { return Size; } + + typedef const char *const_iterator; + const char *begin() const { return Start; } + const char *end() const { return Start + Size; } + + char operator [](size_t index) const { return Start[index]; } + + operator std::string() { std::string Str; Str.assign(Start, Size); return Str; } +}; + +int stringcasecmp(const char *lhsb, const char *lhse, const char *rhs); +inline int stringcasecmp(const srkString &lhs, const char *rhs) { + return stringcasecmp(lhs.Start, lhs.Start + lhs.Size, rhs); +} + +int stringcmp(const std::string &lhs, const char *rhsb, const char *rhse); +inline bool operator ==(const std::string &lhs, const srkString &rhs) { + return stringcmp(lhs, rhs.begin(), rhs.end()) == 0; +} + +#endif diff --git a/apt-pkg/version.h b/apt-pkg/version.h index 49c53a9..692d419 100644 --- a/apt-pkg/version.h +++ b/apt-pkg/version.h @@ -20,7 +20,7 @@ #ifndef PKGLIB_VERSION_H #define PKGLIB_VERSION_H - +#include #include #include -- 2.45.2