From 858f7f833100f0601905f274ec5034c663414a42 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 14 May 2018 15:43:59 -0700 Subject: [PATCH] Fabric: Improved printing of Yoga's `Edges` data structure Summary: Yoga represents concepts like `margin`, `padding` and `position` as `edges` (aka std::array). This diff improves conversion of this data structure to string (primarily for debugging purposes). Reviewed By: fkgozali Differential Revision: D7958241 fbshipit-source-id: 6931c7b5d2395c28821c8daef62f609b13f112c6 --- ReactCommon/fabric/view/conversions.h | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ReactCommon/fabric/view/conversions.h b/ReactCommon/fabric/view/conversions.h index 4f129c2a9..cec142a7b 100644 --- a/ReactCommon/fabric/view/conversions.h +++ b/ReactCommon/fabric/view/conversions.h @@ -337,16 +337,25 @@ inline std::string toString(const std::array &value) } inline std::string toString(const std::array &value) { - return "{" + - toString(value[0]) + ", " + - toString(value[1]) + ", " + - toString(value[2]) + ", " + - toString(value[3]) + ", " + - toString(value[4]) + ", " + - toString(value[5]) + ", " + - toString(value[6]) + ", " + - toString(value[7]) + ", " + - toString(value[8]) + "}"; + static std::array names = { + {"left", "top", "right", "bottom", "start", "end", "horizontal", "vertical", "all"} + }; + + std::string result; + std::string separator = ", "; + + for (int i = 0; i < YGEdgeCount; i++) { + if (value[i].unit == YGUnitUndefined) { + continue; + } + result += names[i] + ": " + toString(value[i]) + separator; + } + + if (!result.empty()) { + result.erase(result.length() - separator.length()); + } + + return "{" + result + "}"; } } // namespace react