本文整理汇总了C++中nsString::ToFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ nsString::ToFloat方法的具体用法?C++ nsString::ToFloat怎么用?C++ nsString::ToFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsString
的用法示例。
在下文中一共展示了nsString::ToFloat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static void
SetProperty(OperatorData* aOperatorData,
nsString aName,
nsString aValue)
{
if (aName.IsEmpty() || aValue.IsEmpty())
return;
// XXX These ones are not kept in the dictionary
// Support for these requires nsString member variables
// maxsize (default: infinity)
// minsize (default: 1)
if (aName.EqualsLiteral("direction")) {
if (aValue.EqualsLiteral("vertical"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_DIRECTION_VERTICAL;
else if (aValue.EqualsLiteral("horizontal"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_DIRECTION_HORIZONTAL;
else return; // invalid value
} else {
bool isLeadingSpace;
if (aName.EqualsLiteral("lspace"))
isLeadingSpace = true;
else if (aName.EqualsLiteral("rspace"))
isLeadingSpace = false;
else return; // input is not applicable
// aValue is assumed to be a digit from 0 to 7
nsresult error = NS_OK;
float space = aValue.ToFloat(&error) / 18.0;
if (NS_FAILED(error)) return;
if (isLeadingSpace)
aOperatorData->mLeadingSpace = space;
else
aOperatorData->mTrailingSpace = space;
}
}
示例2: if
void
SetProperty(OperatorData* aOperatorData,
nsString aName,
nsString aValue)
{
if (!aName.Length() || !aValue.Length())
return;
// XXX These ones are not kept in the dictionary
// Support for these requires nsString member variables
// maxsize (default: infinity)
// minsize (default: 1)
if (aValue.EqualsLiteral("true")) {
// see if we should enable flags with default value=false
if (aName.EqualsLiteral("fence"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_FENCE;
else if (aName.EqualsLiteral("accent"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_ACCENT;
else if (aName.EqualsLiteral("largeop"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_LARGEOP;
else if (aName.EqualsLiteral("separator"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_SEPARATOR;
else if (aName.EqualsLiteral("movablelimits"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_MOVABLELIMITS;
}
else if (aValue.EqualsLiteral("false")) {
// see if we should disable flags with default value=true
if (aName.EqualsLiteral("symmetric"))
aOperatorData->mFlags &= ~NS_MATHML_OPERATOR_SYMMETRIC;
}
else if (aName.EqualsLiteral("stretchy") &&
(1 == aOperatorData->mStr.Length())) {
if (aValue.EqualsLiteral("vertical"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY_VERT;
else if (aValue.EqualsLiteral("horizontal"))
aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY_HORIZ;
else return; // invalid value
if (kNotFound == nsMathMLOperators::FindStretchyOperator(aOperatorData->mStr[0])) {
gStretchyOperatorArray->AppendElement(aOperatorData);
}
}
else {
PRInt32 i = 0;
float space = 0.0f;
PRBool isLeftSpace;
if (aName.EqualsLiteral("lspace"))
isLeftSpace = PR_TRUE;
else if (aName.EqualsLiteral("rspace"))
isLeftSpace = PR_FALSE;
else return; // input is not applicable
// See if it is a numeric value (unit is assumed to be 'em')
if (nsCRT::IsAsciiDigit(aValue[0])) {
PRInt32 error = 0;
space = aValue.ToFloat(&error);
if (error) return;
}
// See if it is one of the 'namedspace' (ranging 1/18em...7/18em)
else if (aValue.EqualsLiteral("veryverythinmathspace")) i = 1;
else if (aValue.EqualsLiteral("verythinmathspace")) i = 2;
else if (aValue.EqualsLiteral("thinmathspace")) i = 3;
else if (aValue.EqualsLiteral("mediummathspace")) i = 4;
else if (aValue.EqualsLiteral("thickmathspace")) i = 5;
else if (aValue.EqualsLiteral("verythickmathspace")) i = 6;
else if (aValue.EqualsLiteral("veryverythickmathspace")) i = 7;
if (0 != i) // it was a namedspace value
space = float(i)/float(18);
if (isLeftSpace)
aOperatorData->mLeftSpace = space;
else
aOperatorData->mRightSpace = space;
}
}
示例3: test_tofloat_helper
static bool test_tofloat_helper(const nsString& aStr, float aExpected, bool aSuccess)
{
int32_t result;
return aStr.ToFloat(&result) == aExpected &&
aSuccess ? result == NS_OK : result != NS_OK;
}