1010namespace facebook {
1111namespace react {
1212
13- std::string DebugStringConvertible::getDebugChildrenDescription (int level) const {
13+ std::string DebugStringConvertible::getDebugChildrenDescription (DebugStringConvertibleOptions options, int depth) const {
14+ if (depth >= options.maximumDepth ) {
15+ return " " ;
16+ }
17+
1418 std::string childrenString = " " ;
1519
1620 for (auto child : getDebugChildren ()) {
17- childrenString += child->getDebugDescription (level + 1 );
21+ childrenString += child->getDebugDescription (options, depth + 1 );
1822 }
1923
2024 return childrenString;
2125}
2226
23- std::string DebugStringConvertible::getDebugPropsDescription (int level) const {
27+ std::string DebugStringConvertible::getDebugPropsDescription (DebugStringConvertibleOptions options, int depth) const {
28+ if (depth >= options.maximumDepth ) {
29+ return " " ;
30+ }
31+
2432 std::string propsString = " " ;
2533
2634 for (auto prop : getDebugProps ()) {
2735 auto name = prop->getDebugName ();
2836 auto value = prop->getDebugValue ();
29- auto children = prop->getDebugPropsDescription (level + 1 );
37+ auto children = prop->getDebugPropsDescription (options, depth + 1 );
3038 auto valueAndChildren = value + (children.empty () ? " " : " (" + children + " )" );
3139 propsString += " " + name + (valueAndChildren.empty () ? " " : " =" + valueAndChildren);
3240 }
@@ -39,16 +47,19 @@ std::string DebugStringConvertible::getDebugPropsDescription(int level) const {
3947 return propsString;
4048}
4149
42- std::string DebugStringConvertible::getDebugDescription (int level ) const {
50+ std::string DebugStringConvertible::getDebugDescription (DebugStringConvertibleOptions options, int depth ) const {
4351 std::string nameString = getDebugName ();
4452 std::string valueString = getDebugValue ();
45- std::string childrenString = getDebugChildrenDescription (level);
46- std::string propsString = getDebugPropsDescription (level);
53+ std::string childrenString = getDebugChildrenDescription (options, depth + 1 );
54+ std::string propsString = getDebugPropsDescription (options, depth /* The first-level props are considered as same-depth things. */ );
55+
56+ std::string leading = options.format ? std::string (depth, ' \t ' ) : " " ;
57+ std::string trailing = options.format ? " \n " : " " ;
4758
48- return " <" + nameString +
59+ return leading + " <" + nameString +
4960 (valueString.empty () ? " " : " =" + valueString) +
5061 (propsString.empty () ? " " : " " + propsString) +
51- (childrenString.empty () ? " />" : " >" + childrenString + " </" + nameString + " >" );
62+ (childrenString.empty () ? " />" + trailing : " >" + trailing + childrenString + leading + " </" + nameString + " >" + trailing );
5263}
5364
5465std::string DebugStringConvertible::getDebugName () const {
0 commit comments