本文整理汇总了C++中folly::dynamic::asString方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::asString方法的具体用法?C++ dynamic::asString怎么用?C++ dynamic::asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::dynamic
的用法示例。
在下文中一共展示了dynamic::asString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: phpSerialize
fbstring phpSerialize(const folly::dynamic& d) {
if (d.isNull()) {
return "N;";
}
if (d.isBool()) {
return d.asBool() ? "b:1;" : "b:0;";
}
if (d.isInt()) {
return "i:" + d.asString() + ";";
}
if (d.isDouble()) {
return "d:" + d.asString() + ";";
}
if (d.isString()) {
auto str = d.asString();
return folly::to<fbstring>("s:", str.size(), ":\"", str, "\";");
}
if (d.isArray()) {
fbstring ret = folly::to<fbstring>("a:", d.size(), ":{");
int i = 0;
for (auto &v : d) {
ret += folly::to<fbstring>("i:", i, ";", phpSerialize(v));
}
return ret + "};";
}
if (d.isObject()) {
fbstring ret = folly::to<fbstring>("a:", d.size(), ":{");
int nextindex = 0;
for (auto &k : d.keys()) {
if (k.isNull()) {
ret += "i:0;";
if (nextindex <= 0) {
nextindex = 1;
}
} else if (k.isInt() || k.isDouble()) {
int i = k.asInt();
ret += folly::to<fbstring>("i:", i, ";");
if (nextindex <= i) {
nextindex = i + 1;
}
} else if (k.isString()) {
ret += folly::to<fbstring>("s:", k.size(), ":\"",
escapeCpp(k.asString()), "\";");
} else {
/* Should never be reached, but cover it to be safe */
ret += folly::to<fbstring>("i:", nextindex++, ";");
}
ret += phpSerialize(d[k]);
}
return ret + "};";
}
throw std::logic_error("Unhandled dynamic type in php serialization");
return "N;";
}
示例2: yogaStyleDisplayFromDynamic
YGDisplay yogaStyleDisplayFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "flex") { return YGDisplayFlex; }
if (stringValue == "none") { return YGDisplayNone; }
abort();
}
示例3: kindOfFromDynamic
// Parse type from a descriptive string, e.g. "int", "bool", etc...
static DataType kindOfFromDynamic(const folly::dynamic& t) {
if (!t.isString()) {
return KindOfInvalid;
}
// If you hit this assert, the IDL contains "type": "Array"; you need to
// use one of {Int64,String,Variant}{Vec,Map} instead.
//
// These are still KindOfArray, not the HH types.
assert(t.asString() != "Array");
auto it = g_kindOfMap.find(t.asString());
if (it == g_kindOfMap.end()) {
return KindOfObject;
}
return it->second;
}
示例4: yogaStylePositionTypeFromDynamic
YGPositionType yogaStylePositionTypeFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "relative") { return YGPositionTypeRelative; }
if (stringValue == "absolute") { return YGPositionTypeAbsolute; }
abort();
}
示例5: yogaStyleDirectionFromDynamic
YGDirection yogaStyleDirectionFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "inherit") { return YGDirectionInherit; }
if (stringValue == "ltr") { return YGDirectionLTR; }
if (stringValue == "rtl") { return YGDirectionRTL; }
abort();
}
示例6: yogaStyleOverflowFromDynamic
YGOverflow yogaStyleOverflowFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "visible") { return YGOverflowVisible; }
if (stringValue == "hidden") { return YGOverflowHidden; }
if (stringValue == "scroll") { return YGOverflowScroll; }
abort();
}
示例7: yogaStyleWrapFromDynamic
YGWrap yogaStyleWrapFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "no-wrap") { return YGWrapNoWrap; }
if (stringValue == "wrap") { return YGWrapWrap; }
if (stringValue == "wrap-reverse") { return YGWrapWrapReverse; }
abort();
}
示例8: yogaStyleFlexDirectionFromDynamic
YGFlexDirection yogaStyleFlexDirectionFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "column") { return YGFlexDirectionColumn; }
if (stringValue == "column-reverse") { return YGFlexDirectionColumnReverse; }
if (stringValue == "row") { return YGFlexDirectionRow; }
if (stringValue == "row-reverse") { return YGFlexDirectionRowReverse; }
abort();
}
示例9: yogaStyleOptionalFloatFromDynamic
YGFloatOptional yogaStyleOptionalFloatFromDynamic(const folly::dynamic &value) {
if (value.isNumber()) {
return YGFloatOptional(value.asDouble());
} else if (value.isString()) {
const auto stringValue = value.asString();
if (stringValue == "auto") {
return YGFloatOptional();
}
}
abort();
}
示例10: yogaStyleJustifyFromDynamic
YGJustify yogaStyleJustifyFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "flex-start") { return YGJustifyFlexStart; }
if (stringValue == "center") { return YGJustifyCenter; }
if (stringValue == "flex-end") { return YGJustifyFlexEnd; }
if (stringValue == "space-between") { return YGJustifySpaceBetween; }
if (stringValue == "space-around") { return YGJustifySpaceAround; }
if (stringValue == "space-evenly") { return YGJustifySpaceEvenly; }
abort();
}
示例11: yogaStyleAlignFromDynamic
YGAlign yogaStyleAlignFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "auto") { return YGAlignAuto; }
if (stringValue == "flex-start") { return YGAlignFlexStart; }
if (stringValue == "center") { return YGAlignCenter; }
if (stringValue == "flex-end") { return YGAlignFlexEnd; }
if (stringValue == "stretch") { return YGAlignStretch; }
if (stringValue == "baseline") { return YGAlignBaseline; }
if (stringValue == "between") { return YGAlignSpaceBetween; }
if (stringValue == "space-around") { return YGAlignSpaceAround; }
abort();
}
示例12: typeString
fbstring typeString(const folly::dynamic& typeNode, bool isReturnType) {
if (!typeNode.isString()) {
return "void";
}
auto typeIt = g_typeMap.find(typeNode.asString());
if (typeIt == g_typeMap.end()) {
return (isReturnType ? "HPHP::Object" : "HPHP::Object const&");
}
auto& type = typeIt->second;
if (!isReturnType && isTypeCppIndirectPass(type)) {
return type + " const&";
} else {
return type;
}
}
示例13: yogaStyleValueFromDynamic
YGValue yogaStyleValueFromDynamic(const folly::dynamic &value) {
if (value.isNumber()) {
float x = value.asDouble();
return { x, YGUnitPoint };
} else if (value.isString()) {
const auto stringValue = value.asString();
if (stringValue == "auto") {
return { YGUndefined, YGUnitAuto };
} else {
if (stringValue.back() == '%') {
return { folly::to<float>(stringValue.substr(stringValue.length() - 1)), YGUnitPercent };
} else {
return { folly::to<float>(stringValue), YGUnitPoint };
}
}
}
return YGValueUndefined;
}