当前位置: 首页>>代码示例>>C++>>正文


C++ nsAString::AppendFloat方法代码示例

本文整理汇总了C++中nsAString::AppendFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::AppendFloat方法的具体用法?C++ nsAString::AppendFloat怎么用?C++ nsAString::AppendFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nsAString的用法示例。


在下文中一共展示了nsAString::AppendFloat方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
nsSVGNumberPair::GetBaseValueString(nsAString &aValueAsString) const
{
  aValueAsString.Truncate();
  aValueAsString.AppendFloat(mBaseVal[0]);
  if (mBaseVal[0] != mBaseVal[1]) {
    aValueAsString.AppendLiteral(", ");
    aValueAsString.AppendFloat(mBaseVal[1]);
  }
}
开发者ID:KWierso,项目名称:releases-mozilla-central,代码行数:10,代码来源:nsSVGNumberPair.cpp

示例2: switch

void
StyleInfo::TextIndent(nsAString& aValue)
{
  aValue.Truncate();

  const nsStyleCoord& styleCoord =
    mStyleContext->GetStyleText()->mTextIndent;

  nscoord coordVal;
  switch (styleCoord.GetUnit()) {
    case eStyleUnit_Coord:
      coordVal = styleCoord.GetCoordValue();
      break;

    case eStyleUnit_Percent:
    {
      nsIFrame* frame = mElement->GetPrimaryFrame();
      nsIFrame* containerFrame = frame->GetContainingBlock();
      nscoord percentageBase = containerFrame->GetContentRect().width;
      coordVal = NSCoordSaturatingMultiply(percentageBase,
                                           styleCoord.GetPercentValue());
      break;
    }
  }

  aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
  aValue.AppendLiteral("px");
}
开发者ID:Anachid,项目名称:mozilla-central,代码行数:28,代码来源:StyleInfo.cpp

示例3: langTagIter

void
nsNumberControlFrame::GetValueOfAnonTextControl(nsAString& aValue)
{
  if (!mTextField) {
    aValue.Truncate();
    return;
  }

  HTMLInputElement::FromContent(mTextField)->GetValue(aValue);

#ifdef ENABLE_INTL_API
  // Here we need to de-localize any number typed in by the user. That is, we
  // need to convert it from the number format of the user's language, region,
  // etc. to the format that the HTML 5 spec defines to be a "valid
  // floating-point number":
  //
  //   http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#floating-point-numbers
  //
  // so that it can be parsed by functions like HTMLInputElement::
  // StringToDecimal (the HTML-5-conforming parsing function) which don't know
  // how to handle numbers that are formatted differently (for example, with
  // non-ASCII digits, with grouping separator characters or with a decimal
  // separator character other than '.').
  //
  // We need to be careful to avoid normalizing numbers that are already
  // formatted for a locale that matches the format of HTML 5's "valid
  // floating-point number" and have no grouping separator characters. (In
  // other words we want to return the number as specified by the user, not the
  // de-localized serialization, since the latter will normalize the value.)
  // For example, if the user's locale is English and the user types in "2e2"
  // then inputElement.value should be "2e2" and not "100". This is because
  // content (and tests) expect us to avoid "normalizing" the number that the
  // user types in if it's not necessary in order to make sure it conforms to
  // HTML 5's "valid floating-point number" format.
  //
  // Note that we also need to be careful when trying to avoid normalization.
  // For example, just because "1.234" _looks_ like a valid floating-point
  // number according to the spec does not mean that it should be returned
  // as-is. If the user's locale is German, then this represents the value
  // 1234, not 1.234, so it still needs to be de-localized. Alternatively, if
  // the user's locale is English and they type in "1,234" we _do_ need to
  // normalize the number to "1234" because HTML 5's valid floating-point
  // number format does not allow the ',' grouping separator. We can detect all
  // the cases where we need to convert by seeing if the locale-specific
  // parsing function understands the user input to mean the same thing as the
  // HTML-5-conforming parsing function. If so, then we should return the value
  // as-is to avoid normalization. Otherwise, we return the de-localized
  // serialization.
  ICUUtils::LanguageTagIterForContent langTagIter(mContent);
  double value = ICUUtils::ParseNumber(aValue, langTagIter);
  if (NS_finite(value) &&
      value != HTMLInputElement::StringToDecimal(aValue).toDouble()) {
    aValue.Truncate();
    aValue.AppendFloat(value);
  }
#endif
  // else, we return whatever FromContent put into aValue (the number as typed
  // in by the user)
}
开发者ID:nightahul,项目名称:gecko-dev,代码行数:59,代码来源:nsNumberControlFrame.cpp

示例4:

void
StyleInfo::Margin(css::Side aSide, nsAString& aValue)
{
  aValue.Truncate();

  nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
  aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
  aValue.AppendLiteral("px");
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:9,代码来源:StyleInfo.cpp

示例5: langTagIter

void
nsNumberControlFrame::GetValueOfAnonTextControl(nsAString& aValue)
{
  if (!mTextField) {
    aValue.Truncate();
    return;
  }

  HTMLInputElement::FromContent(mTextField)->GetValue(aValue);

#ifdef ENABLE_INTL_API
  // Here we need to de-localize any number typed in by the user. That is, we
  // need to convert it from the number format of the user's language, region,
  // etc. to the format that the HTML 5 spec defines to be a "valid
  // floating-point number":
  //
  //   http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#floating-point-numbers
  //
  // This is necessary to allow the number that we return to be parsed by
  // functions like HTMLInputElement::StringToDecimal (the HTML-5-conforming
  // parsing function) which don't know how to handle numbers that are
  // formatted differently (for example, with non-ASCII digits, with grouping
  // separator characters or with a decimal separator character other than
  // '.').

  ICUUtils::LanguageTagIterForContent langTagIter(mContent);
  double value = ICUUtils::ParseNumber(aValue, langTagIter);
  if (!IsFinite(value)) {
    aValue.Truncate();
    return;
  }
  if (value == HTMLInputElement::StringToDecimal(aValue).toDouble()) {
    // We want to preserve the formatting of the number as typed in by the user
    // whenever possible. Since the localized serialization parses to the same
    // number as the de-localized serialization, we can do that. This helps
    // prevent normalization of input such as "2e2" (which would otherwise be
    // converted to "200"). Content relies on this.
    //
    // Typically we will only get here for locales in which numbers are
    // formatted in the same way as they are for HTML5's "valid floating-point
    // number" format.
    return;
  }
  // We can't preserve the formatting, otherwise functions such as
  // HTMLInputElement::StringToDecimal would incorrectly process the number
  // input by the user. For example, "12.345" with lang=de de-localizes as
  // 12345, but HTMLInputElement::StringToDecimal would mistakenly parse it as
  // 12.345. Another example would be "12,345" with lang=de which de-localizes
  // as 12.345, but HTMLInputElement::StringToDecimal would parse it to NaN.
  aValue.Truncate();
  aValue.AppendFloat(value);
#endif
}
开发者ID:cliqz-oss,项目名称:browser-f,代码行数:53,代码来源:nsNumberControlFrame.cpp

示例6: switch

void
StyleInfo::TextIndent(nsAString& aValue)
{
  aValue.Truncate();

  const nsStyleCoord& styleCoord =
    mStyleContext->GetStyleText()->mTextIndent;

  nscoord coordVal = 0;
  switch (styleCoord.GetUnit()) {
    case eStyleUnit_Coord:
      coordVal = styleCoord.GetCoordValue();
      break;

    case eStyleUnit_Percent:
    {
      nsIFrame* frame = mElement->GetPrimaryFrame();
      nsIFrame* containerFrame = frame->GetContainingBlock();
      nscoord percentageBase = containerFrame->GetContentRect().width;
      coordVal = NSCoordSaturatingMultiply(percentageBase,
                                           styleCoord.GetPercentValue());
      break;
    }

    case eStyleUnit_Null:
    case eStyleUnit_Normal:
    case eStyleUnit_Auto:
    case eStyleUnit_None:
    case eStyleUnit_Factor:
    case eStyleUnit_Degree:
    case eStyleUnit_Grad:
    case eStyleUnit_Radian:
    case eStyleUnit_Turn:
    case eStyleUnit_Integer:
    case eStyleUnit_Enumerated:
    case eStyleUnit_Calc:
      break;
  }

  aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
  aValue.AppendLiteral("px");
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:42,代码来源:StyleInfo.cpp

示例7:

void
nsSVGNumber2::GetBaseValueString(nsAString & aValueAsString)
{
  aValueAsString.Truncate();
  aValueAsString.AppendFloat(mBaseVal);
}
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:6,代码来源:nsSVGNumber2.cpp

示例8: GetMiscContainer

void
nsAttrValue::ToString(nsAString& aResult) const
{
  MiscContainer* cont = nsnull;
  if (BaseType() == eOtherBase) {
    cont = GetMiscContainer();
    void* ptr = MISC_STR_PTR(cont);
    if (ptr) {
      if (static_cast<ValueBaseType>(cont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) ==
          eStringBase) {
        nsStringBuffer* str = static_cast<nsStringBuffer*>(ptr);
        if (str) {
          str->ToString(str->StorageSize()/sizeof(PRUnichar) - 1, aResult);
          return;
        }
      } else {
        nsIAtom *atom = static_cast<nsIAtom*>(ptr);
        atom->ToString(aResult);
        return;
      }
    }
  }

  switch(Type()) {
    case eString:
    {
      nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
      if (str) {
        str->ToString(str->StorageSize()/sizeof(PRUnichar) - 1, aResult);
      }
      else {
        aResult.Truncate();
      }
      break;
    }
    case eAtom:
    {
      nsIAtom *atom = static_cast<nsIAtom*>(GetPtr());
      atom->ToString(aResult);

      break;
    }
    case eInteger:
    {
      nsAutoString intStr;
      intStr.AppendInt(GetIntegerValue());
      aResult = intStr;

      break;
    }
#ifdef DEBUG
    case eColor:
    {
      NS_NOTREACHED("color attribute without string data");
      aResult.Truncate();
      break;
    }
#endif
    case eEnum:
    {
      GetEnumString(aResult, PR_FALSE);
      break;
    }
    case ePercent:
    {
      nsAutoString intStr;
      intStr.AppendInt(cont ? cont->mPercent : GetIntInternal());
      aResult = intStr + NS_LITERAL_STRING("%");

      break;
    }
    case eCSSStyleRule:
    {
      aResult.Truncate();
      MiscContainer *container = GetMiscContainer();
      css::Declaration *decl = container->mCSSStyleRule->GetDeclaration();
      if (decl) {
        decl->ToString(aResult);
      }
      const_cast<nsAttrValue*>(this)->SetMiscAtomOrString(&aResult);

      break;
    }
    case eSVGValue:
    {
      GetMiscContainer()->mSVGValue->GetValueString(aResult);
      break;
    }
    case eDoubleValue:
    {
      aResult.Truncate();
      aResult.AppendFloat(GetDoubleValue());
      break;
    }
    default:
    {
      aResult.Truncate();
      break;
    }
  }
//.........这里部分代码省略.........
开发者ID:Egyptghost1,项目名称:DOMinator,代码行数:101,代码来源:nsAttrValue.cpp

示例9: GetMiscContainer

void
nsAttrValue::ToString(nsAString& aResult) const
{
  MiscContainer* cont = nullptr;
  if (BaseType() == eOtherBase) {
    cont = GetMiscContainer();

    if (cont->GetString(aResult)) {
      return;
    }
  }

  switch(Type()) {
    case eString:
    {
      nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
      if (str) {
        str->ToString(str->StorageSize()/sizeof(char16_t) - 1, aResult);
      }
      else {
        aResult.Truncate();
      }
      break;
    }
    case eAtom:
    {
      nsIAtom *atom = static_cast<nsIAtom*>(GetPtr());
      atom->ToString(aResult);

      break;
    }
    case eInteger:
    {
      nsAutoString intStr;
      intStr.AppendInt(GetIntegerValue());
      aResult = intStr;

      break;
    }
#ifdef DEBUG
    case eColor:
    {
      NS_NOTREACHED("color attribute without string data");
      aResult.Truncate();
      break;
    }
#endif
    case eEnum:
    {
      GetEnumString(aResult, false);
      break;
    }
    case ePercent:
    {
      nsAutoString intStr;
      intStr.AppendInt(cont ? cont->mValue.mPercent : GetIntInternal());
      aResult = intStr + NS_LITERAL_STRING("%");

      break;
    }
    case eCSSStyleRule:
    {
      aResult.Truncate();
      MiscContainer *container = GetMiscContainer();
      css::Declaration *decl =
        container->mValue.mCSSStyleRule->GetDeclaration();
      if (decl) {
        decl->ToString(aResult);
      }
      const_cast<nsAttrValue*>(this)->SetMiscAtomOrString(&aResult);

      break;
    }
    case eDoubleValue:
    {
      aResult.Truncate();
      aResult.AppendFloat(GetDoubleValue());
      break;
    }
    case eSVGAngle:
    {
      SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGAngle,
                                    aResult);
      break;
    }
    case eSVGIntegerPair:
    {
      SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGIntegerPair,
                                    aResult);
      break;
    }
    case eSVGLength:
    {
      SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGLength,
                                    aResult);
      break;
    }
    case eSVGLengthList:
    {
      SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGLengthList,
//.........这里部分代码省略.........
开发者ID:70599,项目名称:Waterfox,代码行数:101,代码来源:nsAttrValue.cpp

示例10: if


//.........这里部分代码省略.........
  else if (eCSSUnit_EnumColor == unit) {
    // we can lookup the property in the ColorTable and then
    // get a string mapping the name
    nsCAutoString str;
    if (nsCSSProps::GetColorName(GetIntValue(), str)){
      AppendASCIItoUTF16(str, aResult);
    } else {
      NS_ABORT_IF_FALSE(false, "bad color value");
    }
  }
  else if (eCSSUnit_Color == unit) {
    nscolor color = GetColorValue();
    if (color == NS_RGBA(0, 0, 0, 0)) {
      // Use the strictest match for 'transparent' so we do correct
      // round-tripping of all other rgba() values.
      aResult.AppendLiteral("transparent");
    } else {
      PRUint8 a = NS_GET_A(color);
      if (a < 255) {
        aResult.AppendLiteral("rgba(");
      } else {
        aResult.AppendLiteral("rgb(");
      }

      NS_NAMED_LITERAL_STRING(comma, ", ");

      aResult.AppendInt(NS_GET_R(color), 10);
      aResult.Append(comma);
      aResult.AppendInt(NS_GET_G(color), 10);
      aResult.Append(comma);
      aResult.AppendInt(NS_GET_B(color), 10);
      if (a < 255) {
        aResult.Append(comma);
        aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
      }
      aResult.Append(PRUnichar(')'));
    }
  }
  else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) {
    aResult.Append(NS_LITERAL_STRING("url("));
    nsStyleUtil::AppendEscapedCSSString(
      nsDependentString(GetOriginalURLValue()), aResult);
    aResult.Append(NS_LITERAL_STRING(")"));
  }
  else if (eCSSUnit_Element == unit) {
    aResult.Append(NS_LITERAL_STRING("-moz-element(#"));
    nsAutoString tmpStr;
    GetStringValue(tmpStr);
    nsStyleUtil::AppendEscapedCSSIdent(tmpStr, aResult);
    aResult.Append(NS_LITERAL_STRING(")"));
  }
  else if (eCSSUnit_Percent == unit) {
    aResult.AppendFloat(GetPercentValue() * 100.0f);
  }
  else if (eCSSUnit_Percent < unit) {  // length unit
    aResult.AppendFloat(GetFloatValue());
  }
  else if (eCSSUnit_Gradient == unit) {
    nsCSSValueGradient* gradient = GetGradientValue();

    if (gradient->mIsRepeating) {
      if (gradient->mIsRadial)
        aResult.AppendLiteral("-moz-repeating-radial-gradient(");
      else
        aResult.AppendLiteral("-moz-repeating-linear-gradient(");
    } else {
开发者ID:krellian,项目名称:mozilla-central,代码行数:67,代码来源:nsCSSValue.cpp

示例11:

// Convenient way to append things as floats, not doubles.  We use this because
// we only want to output about 6 digits of precision for our matrix()
// functions, to preserve the behavior we used to have when we used
// AppendPrintf.
static void
AppendFloat(nsAString& aStr, float f)
{
  aStr.AppendFloat(f);
}
开发者ID:artines1,项目名称:gecko-dev,代码行数:9,代码来源:DOMMatrix.cpp


注:本文中的nsAString::AppendFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。