Skip to content

Added 'format' argument so the result of the substr can be processed#258

Merged
axunonb merged 1 commit intoaxuno:version/v3.0from
axunonb:pr-substring-with-nested-format
Mar 8, 2022
Merged

Added 'format' argument so the result of the substr can be processed#258
axunonb merged 1 commit intoaxuno:version/v3.0from
axunonb:pr-substring-with-nested-format

Conversation

@axunonb
Copy link
Copy Markdown
Member

@axunonb axunonb commented Mar 8, 2022

Enhanced SubStringFormatter

The only syntax in v2:

{ string : substr(start,length) }

Added optional format-placeholder in v3

{ string : substr(start,length) : {format-placeholder} }

value: Only strings can be processed. Other objects cause a FormattingException.

arguments: The start position and the lenght of the sub-string.

NEW
format-placeholder: A nested Placeholder that lets you format the result of the sub-string operation.

Examples with Format argument

The Format argument must contain nested Placeholder, and may contain literal text.

Convert the substring to lower-case

Smart.Format("{0:substr(0,2):{ToLower}}", "ABC");
//                          |        |
//                          + format +
//                             arg
// Outputs: "ab"

Format the substring chars with the ListFormatter

Format the substring with literal text and placeholder.

smart.Format("{0:substr(0,2):First 2 chars\\: {ToLower.ToCharArray:list:'{}'| and }}", "ABC");
// Outputs: "First 2 chars: 'a' and 'b'"

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2022

Codecov Report

Merging #258 (07e63ae) into version/v3.0 (9d6c444) will increase coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           version/v3.0   #258   +/-   ##
===========================================
  Coverage            96%    96%           
===========================================
  Files                91     91           
  Lines              3154   3162    +8     
===========================================
+ Hits               3036   3044    +8     
  Misses              118    118           
Impacted Files Coverage Δ
src/SmartFormat/Extensions/SubStringFormatter.cs 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d6c444...07e63ae. Read the comment docs.

@axunonb axunonb merged commit 865f49a into axuno:version/v3.0 Mar 8, 2022
@axunonb axunonb deleted the pr-substring-with-nested-format branch March 8, 2022 20:47
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant