Valentin Shergin 9570d7d490 Fabric: Unifying usage of autos
Summary:
I was watching a classic magnificent talk about modern C++ by Herb Sutter and I was totally sold on double down on using `auto` in our codebase. Surprisingly, 95% of the code base already follows Herb's guidence; I just changed the last 5% to make it consistent.
All those changes must work *exactly* like it was before.
The talk: https://youtu.be/xnqTKD8uD64?t=28m25s

Reviewed By: mdvacca

Differential Revision: D9753301

fbshipit-source-id: 9629aa485a5d6e51806cc96306c297284d4f90b8
2018-09-10 16:50:02 -07:00

77 lines
2.1 KiB
C++

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "AttributedString.h"
#include <fabric/debug/DebugStringConvertibleItem.h>
namespace facebook {
namespace react {
using Fragment = AttributedString::Fragment;
using Fragments = AttributedString::Fragments;
void AttributedString::appendFragment(const Fragment &fragment) {
ensureUnsealed();
fragments_.push_back(fragment);
}
void AttributedString::prependFragment(const Fragment &fragment) {
ensureUnsealed();
fragments_.insert(fragments_.begin(), fragment);
}
void AttributedString::appendAttributedString(const AttributedString &attributedString) {
ensureUnsealed();
fragments_.insert(fragments_.end(), attributedString.fragments_.begin(), attributedString.fragments_.end());
}
void AttributedString::prependAttributedString(const AttributedString &attributedString) {
ensureUnsealed();
fragments_.insert(fragments_.begin(), attributedString.fragments_.begin(), attributedString.fragments_.end());
}
const std::vector<Fragment> &AttributedString::getFragments() const {
return fragments_;
}
std::string AttributedString::getString() const {
auto string = std::string {};
for (const auto &fragment : fragments_) {
string += fragment.string;
}
return string;
}
#pragma mark - DebugStringConvertible
SharedDebugStringConvertibleList AttributedString::getDebugChildren() const {
auto list = SharedDebugStringConvertibleList {};
for (auto &&fragment : fragments_) {
auto propsList = fragment.textAttributes.DebugStringConvertible::getDebugProps();
if (fragment.shadowNode) {
propsList.push_back(std::make_shared<DebugStringConvertibleItem>("shadowNode", fragment.shadowNode->getDebugDescription()));
}
list.push_back(
std::make_shared<DebugStringConvertibleItem>(
"Fragment",
fragment.string,
SharedDebugStringConvertibleList(),
propsList
)
);
}
return list;
}
} // namespace react
} // namespace facebook