MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getString

Method getString

src/Base/Unit.cpp:239–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239std::string Unit::getString() const
240{
241 auto buildSubStr = [&](auto index) {
242 const std::string unitStrString {unitSymbols.at(index)};
243 const auto absol {abs(_exps.at(index))};
244
245 return absol <= 1 ? unitStrString
246 : fmt::format("{}^{}", unitStrString, std::to_string(absol));
247 };
248
249 auto buildStr = [&](auto indexes) {
250 std::vector<std::string> subStrings {};
251 std::transform(indexes.begin(), indexes.end(), std::back_inserter(subStrings), buildSubStr);
252
253 return fmt::format("{}", fmt::join(subStrings, "*"));
254 };
255
256 //------------------------------------------------------------------------------
257
258 auto [posValIndexes, negValIndexes] = nonZeroValsIndexes();
259 auto numeratorStr = buildStr(posValIndexes);
260 if (negValIndexes.empty()) {
261 return numeratorStr;
262 }
263
264 auto denominatorStr = buildStr(negValIndexes);
265
266 return fmt::format(
267 "{}/{}",
268 numeratorStr.empty() ? "1" : numeratorStr,
269 negValIndexes.size() > 1 ? fmt::format("({})", denominatorStr) : denominatorStr
270 );
271}
272
273std::string Unit::representation() const
274{

Callers 15

isSameMethod · 0.45
getPropertyComponentsMethod · 0.45
toPersistentStringMethod · 0.45
replaceObjectMethod · 0.45
updateLabelReferenceMethod · 0.45
relabeledDocumentMethod · 0.45
toStringMethod · 0.45
resolveMethod · 0.45
getDocumentMethod · 0.45
getDepLabelsMethod · 0.45
getStringListMethod · 0.45

Calls 9

absFunction · 0.85
atMethod · 0.80
formatFunction · 0.50
to_stringFunction · 0.50
transformFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.36