MCPcopy Create free account
hub / github.com/catboost/catboost / FormatString

Function FormatString

library/cpp/yt/string/format-inl.h:421–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419
420template <class TStringBuilder>
421void FormatString(TStringBuilder* builder, TStringBuf value, TStringBuf spec)
422{
423 if (!spec) {
424 builder->AppendString(value);
425 return;
426 }
427
428 // Parse alignment.
429 bool alignLeft = false;
430 const char* current = spec.begin();
431 if (*current == '-') {
432 alignLeft = true;
433 ++current;
434 }
435
436 bool hasAlign = false;
437 int alignSize = 0;
438 while (*current >= '0' && *current <= '9') {
439 hasAlign = true;
440 alignSize = 10 * alignSize + (*current - '0');
441 if (alignSize > 1000000) {
442 builder->AppendString(TStringBuf("<alignment overflow>"));
443 return;
444 }
445 ++current;
446 }
447
448 int padding = 0;
449 bool padLeft = false;
450 bool padRight = false;
451 if (hasAlign) {
452 padding = alignSize - value.size();
453 if (padding < 0) {
454 padding = 0;
455 }
456 padLeft = !alignLeft;
457 padRight = alignLeft;
458 }
459
460 bool singleQuotes = false;
461 bool doubleQuotes = false;
462 bool escape = false;
463 while (current < spec.end()) {
464 switch (*current++) {
465 case 'q':
466 singleQuotes = true;
467 break;
468 case 'Q':
469 doubleQuotes = true;
470 break;
471 case 'h':
472 escape = true;
473 break;
474 }
475 }
476
477 if (padLeft) {
478 builder->AppendChar(' ', padding);

Callers 1

FormatValueFunction · 0.70

Calls 5

AppendCharMethod · 0.80
AppendStringMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected