diff options
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/hashsum_template.h | 26 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 7 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 7 |
3 files changed, 37 insertions, 3 deletions
diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h index d0ea0971e..42248f6ac 100644 --- a/apt-pkg/contrib/hashsum_template.h +++ b/apt-pkg/contrib/hashsum_template.h @@ -13,6 +13,9 @@ #include <string> #include <cstring> +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include <apt-pkg/string_view.h> +#endif #include <apt-pkg/strutl.h> @@ -80,7 +83,16 @@ class HashSumValue { return Hex2Num(Str,Sum,sizeof(Sum)); } - +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN bool Set(APT::StringView Str) + { + return Hex2Num(Str,Sum,sizeof(Sum)); + } + APT_HIDDEN bool Set(const char *Str) + { + return Hex2Num(APT::StringView(Str),Sum,sizeof(Sum)); + } +#endif inline void Set(unsigned char S[N/8]) { for (int I = 0; I != sizeof(Sum); ++I) @@ -92,6 +104,18 @@ class HashSumValue memset(Sum,0,sizeof(Sum)); Set(Str); } +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN explicit HashSumValue(APT::StringView const &Str) + { + memset(Sum,0,sizeof(Sum)); + Set(Str); + } + APT_HIDDEN explicit HashSumValue(const char *Str) + { + memset(Sum,0,sizeof(Sum)); + Set(Str); + } +#endif HashSumValue() { memset(Sum,0,sizeof(Sum)); diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index b9bfc2c98..856e5ee9f 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1114,12 +1114,17 @@ 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(APT::StringView(Str), Num, Length); +} + +bool Hex2Num(const APT::StringView 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 (auto I = Str.begin(); I != Str.end();J++, I += 2) { int first_half = HexDigit(I[0]); int second_half; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index a8bbc38af..c5c8e2382 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -22,6 +22,9 @@ #include <cstring> #include <vector> #include <iostream> +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include <apt-pkg/string_view.h> +#endif #include <time.h> #include <stddef.h> @@ -75,7 +78,9 @@ bool StrToNum(const char *Str,unsigned long long &Res,unsigned Len,unsigned Base bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len); bool Base256ToNum(const char *Str,unsigned long long &Res,unsigned int Len); bool Hex2Num(const std::string &Str,unsigned char *Num,unsigned int Length); - +#ifdef APT_PKG_EXPOSE_STRING_VIEW +APT_HIDDEN bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length); +#endif // input changing string split bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); |