View source code
Display the source code in std/string.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.string.column
Compute column number at the end of the printed form of the string, assuming the string starts in the leftmost column, which is numbered starting from 0.
Tab characters are expanded into enough spaces to bring the column number
to the next multiple of tabsize
.
If there are multiple lines in the string, the column number of the last
line is returned.
Prototype
size_t column(Range)( Range str, size_t tabsize = 8 ) if (isSomeString!Range || isInputRange!Range && isSomeChar!(Unqual!(ElementEncodingType!Range)));
Parameters
Name | Description |
---|---|
str | string or InputRange to be analyzed |
tabsize | number of columns a tab character represents |
Returns
column
number
Example
import std.utf : byChar, byWchar, byDchar; assert(column("1234 ") == 5); assert(column("1234 "w) == 5); assert(column("1234 "d) == 5); assert(column("1234 ".byChar()) == 5); assert(column("1234 "w.byWchar()) == 5); assert(column("1234 "d.byDchar()) == 5); // Tab stops are set at 8 spaces by default; tab characters insert enough // spaces to bring the column position to the next multiple of 8. assert(column("\t") == 8); assert(column("1\t") == 8); assert(column("\t1") == 9); assert(column("123\t") == 8); // Other tab widths are possible by specifying it explicitly: assert(column("\t", 4) == 4); assert(column("1\t", 4) == 4); assert(column("\t1", 4) == 5); assert(column("123\t", 4) == 4); // New lines reset the column number. assert(column("abc\n") == 0); assert(column("abc\n1") == 1); assert(column("abcdefg\r1234") == 4); assert(column("abc\u20281") == 1); assert(column("abc\u20291") == 1); assert(column("abc\u00851") == 1); assert(column("abc\u00861") == 5);
Authors
Walter Bright, Andrei Alexandrescu, and Jonathan M Davis