kits/package: allow to set BPackageResolvable to parsed string
Change-Id: I8ebb46b12a8af229d05994eb3cdd2d8180edc903 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7555 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -202,6 +202,10 @@ public:
|
|||||||
bool revisionIsOptional,
|
bool revisionIsOptional,
|
||||||
BPackageVersion& _version,
|
BPackageVersion& _version,
|
||||||
ParseErrorListener* listener = NULL);
|
ParseErrorListener* listener = NULL);
|
||||||
|
static status_t ParseResolvableString(
|
||||||
|
const BString& string,
|
||||||
|
BPackageResolvable& _expression,
|
||||||
|
ParseErrorListener* listener = NULL);
|
||||||
static status_t ParseResolvableExpressionString(
|
static status_t ParseResolvableExpressionString(
|
||||||
const BString& string,
|
const BString& string,
|
||||||
BPackageResolvableExpression& _expression,
|
BPackageResolvableExpression& _expression,
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public:
|
|||||||
|
|
||||||
BString ToString() const;
|
BString ToString() const;
|
||||||
|
|
||||||
|
status_t SetToString(const BString& expressionString);
|
||||||
void SetTo(const BString& name,
|
void SetTo(const BString& name,
|
||||||
const BPackageVersion& version
|
const BPackageVersion& version
|
||||||
= BPackageVersion(),
|
= BPackageVersion(),
|
||||||
|
|||||||
@@ -1156,6 +1156,14 @@ BPackageInfo::ParseVersionString(const BString& string, bool revisionIsOptional,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ status_t
|
||||||
|
BPackageInfo::ParseResolvableString(const BString& string,
|
||||||
|
BPackageResolvable& _expression, ParseErrorListener* listener)
|
||||||
|
{
|
||||||
|
return Parser(listener).ParseResolvable(string, _expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ status_t
|
/*static*/ status_t
|
||||||
BPackageInfo::ParseResolvableExpressionString(const BString& string,
|
BPackageInfo::ParseResolvableExpressionString(const BString& string,
|
||||||
BPackageResolvableExpression& _expression, ParseErrorListener* listener)
|
BPackageResolvableExpression& _expression, ParseErrorListener* listener)
|
||||||
|
|||||||
@@ -106,6 +106,31 @@ BPackageInfo::Parser::ParseVersion(const BString& versionString,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BPackageInfo::Parser::ParseResolvable(const BString& expressionString,
|
||||||
|
BPackageResolvable& _expression)
|
||||||
|
{
|
||||||
|
fPos = expressionString.String();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Token token(TOKEN_STRING, fPos, expressionString.Length());
|
||||||
|
_ParseResolvable(_NextToken(), _expression);
|
||||||
|
} catch (const ParseError& error) {
|
||||||
|
if (fListener != NULL) {
|
||||||
|
int32 offset = error.pos - expressionString.String();
|
||||||
|
fListener->OnError(error.message, 1, offset);
|
||||||
|
}
|
||||||
|
return B_BAD_DATA;
|
||||||
|
} catch (const std::bad_alloc& e) {
|
||||||
|
if (fListener != NULL)
|
||||||
|
fListener->OnError("out of memory", 0, 0);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPackageInfo::Parser::ParseResolvableExpression(const BString& expressionString,
|
BPackageInfo::Parser::ParseResolvableExpression(const BString& expressionString,
|
||||||
BPackageResolvableExpression& _expression)
|
BPackageResolvableExpression& _expression)
|
||||||
@@ -427,6 +452,50 @@ BPackageInfo::Parser::_ParseVersionValue(Token& word, BPackageVersion* value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BPackageInfo::Parser::_ParseResolvable(const Token& token,
|
||||||
|
BPackageResolvable& _value)
|
||||||
|
{
|
||||||
|
if (token.type != TOKEN_STRING) {
|
||||||
|
throw ParseError("expected word (a resolvable name)",
|
||||||
|
token.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 errorPos;
|
||||||
|
if (!_IsValidResolvableName(token.text, &errorPos)) {
|
||||||
|
throw ParseError("invalid character in resolvable name",
|
||||||
|
token.pos + errorPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse version
|
||||||
|
BPackageVersion version;
|
||||||
|
Token op = _NextToken();
|
||||||
|
if (op.type == TOKEN_OPERATOR_ASSIGN) {
|
||||||
|
_ParseVersionValue(&version, true);
|
||||||
|
} else if (op.type == TOKEN_ITEM_SEPARATOR
|
||||||
|
|| op.type == TOKEN_CLOSE_BRACE || op.type == TOKEN_EOF) {
|
||||||
|
_RewindTo(op);
|
||||||
|
} else
|
||||||
|
throw ParseError("expected '=', comma or '}'", op.pos);
|
||||||
|
|
||||||
|
// parse compatible version
|
||||||
|
BPackageVersion compatibleVersion;
|
||||||
|
Token compatible = _NextToken();
|
||||||
|
if (compatible.type == TOKEN_STRING
|
||||||
|
&& (compatible.text == "compat"
|
||||||
|
|| compatible.text == "compatible")) {
|
||||||
|
op = _NextToken();
|
||||||
|
if (op.type == TOKEN_OPERATOR_GREATER_EQUAL) {
|
||||||
|
_ParseVersionValue(&compatibleVersion, true);
|
||||||
|
} else
|
||||||
|
_RewindTo(compatible);
|
||||||
|
} else
|
||||||
|
_RewindTo(compatible);
|
||||||
|
|
||||||
|
_value.SetTo(token.text, version, compatibleVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPackageInfo::Parser::_ParseResolvableExpression(const Token& token,
|
BPackageInfo::Parser::_ParseResolvableExpression(const Token& token,
|
||||||
BPackageResolvableExpression& _value, BString* _basePackage)
|
BPackageResolvableExpression& _value, BString* _basePackage)
|
||||||
@@ -611,44 +680,9 @@ BPackageInfo::Parser::_ParseResolvableList(
|
|||||||
|
|
||||||
virtual void operator()(const Token& token)
|
virtual void operator()(const Token& token)
|
||||||
{
|
{
|
||||||
if (token.type != TOKEN_STRING) {
|
BPackageResolvable expression;
|
||||||
throw ParseError("expected word (a resolvable name)",
|
parser._ParseResolvable(token, expression);
|
||||||
token.pos);
|
value->AddItem(new BPackageResolvable(expression));
|
||||||
}
|
|
||||||
|
|
||||||
int32 errorPos;
|
|
||||||
if (!_IsValidResolvableName(token.text, &errorPos)) {
|
|
||||||
throw ParseError("invalid character in resolvable name",
|
|
||||||
token.pos + errorPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse version
|
|
||||||
BPackageVersion version;
|
|
||||||
Token op = parser._NextToken();
|
|
||||||
if (op.type == TOKEN_OPERATOR_ASSIGN) {
|
|
||||||
parser._ParseVersionValue(&version, true);
|
|
||||||
} else if (op.type == TOKEN_ITEM_SEPARATOR
|
|
||||||
|| op.type == TOKEN_CLOSE_BRACE) {
|
|
||||||
parser._RewindTo(op);
|
|
||||||
} else
|
|
||||||
throw ParseError("expected '=', comma or '}'", op.pos);
|
|
||||||
|
|
||||||
// parse compatible version
|
|
||||||
BPackageVersion compatibleVersion;
|
|
||||||
Token compatible = parser._NextToken();
|
|
||||||
if (compatible.type == TOKEN_STRING
|
|
||||||
&& (compatible.text == "compat"
|
|
||||||
|| compatible.text == "compatible")) {
|
|
||||||
op = parser._NextToken();
|
|
||||||
if (op.type == TOKEN_OPERATOR_GREATER_EQUAL) {
|
|
||||||
parser._ParseVersionValue(&compatibleVersion, true);
|
|
||||||
} else
|
|
||||||
parser._RewindTo(compatible);
|
|
||||||
} else
|
|
||||||
parser._RewindTo(compatible);
|
|
||||||
|
|
||||||
value->AddItem(new BPackageResolvable(token.text, version,
|
|
||||||
compatibleVersion));
|
|
||||||
}
|
}
|
||||||
} resolvableParser(*this, value);
|
} resolvableParser(*this, value);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ public:
|
|||||||
status_t ParseVersion(const BString& versionString,
|
status_t ParseVersion(const BString& versionString,
|
||||||
bool revisionIsOptional,
|
bool revisionIsOptional,
|
||||||
BPackageVersion& _version);
|
BPackageVersion& _version);
|
||||||
|
status_t ParseResolvable(
|
||||||
|
const BString& expressionString,
|
||||||
|
BPackageResolvable& _expression);
|
||||||
status_t ParseResolvableExpression(
|
status_t ParseResolvableExpression(
|
||||||
const BString& expressionString,
|
const BString& expressionString,
|
||||||
BPackageResolvableExpression& _expression);
|
BPackageResolvableExpression& _expression);
|
||||||
@@ -69,6 +72,9 @@ private:
|
|||||||
static void _ParseVersionValue(Token& word,
|
static void _ParseVersionValue(Token& word,
|
||||||
BPackageVersion* value,
|
BPackageVersion* value,
|
||||||
bool revisionIsOptional);
|
bool revisionIsOptional);
|
||||||
|
void _ParseResolvable(
|
||||||
|
const Token& token,
|
||||||
|
BPackageResolvable& _value);
|
||||||
void _ParseResolvableExpression(
|
void _ParseResolvableExpression(
|
||||||
const Token& token,
|
const Token& token,
|
||||||
BPackageResolvableExpression& _value,
|
BPackageResolvableExpression& _value,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <package/PackageResolvable.h>
|
#include <package/PackageResolvable.h>
|
||||||
|
|
||||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||||
|
#include <package/PackageInfo.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
@@ -81,6 +82,18 @@ BPackageResolvable::ToString() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BPackageResolvable::SetToString(const BString& expressionString)
|
||||||
|
{
|
||||||
|
fName.Truncate(0);
|
||||||
|
fVersion.Clear();
|
||||||
|
fCompatibleVersion.Clear();
|
||||||
|
|
||||||
|
return BPackageInfo::ParseResolvableString(expressionString,
|
||||||
|
*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPackageResolvable::SetTo(const BString& name, const BPackageVersion& version,
|
BPackageResolvable::SetTo(const BString& name, const BPackageVersion& version,
|
||||||
const BPackageVersion& compatibleVersion)
|
const BPackageVersion& compatibleVersion)
|
||||||
|
|||||||
Reference in New Issue
Block a user