Exports textpos_t which describes position in text as column and line number. A text is a big string which contains special formatting characters. The only formatting character which is supported by any text function handling UTF-8 encoded strings is the ‘\n’ newline characters which marks the end of a text line.
TextPosition | Exports textpos_t which describes position in text as column and line number. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file TextPosition. |
C-kern/ | Implementation file TextPosition impl. |
Types | |
struct textpos_t | Export textpos_t into global namespace. |
Functions | |
test | |
unittest_string_textpos | Test textpos_t functionality. |
textpos_t | Describes position in text as column and line number. |
column | Column number of the last read character. |
line | Line number of the next unread character. |
prevlastcolumn | Column number of the last character on the previous line. |
lifetime | |
textpos_INIT | Static initializer. |
textpos_FREE | Static initializer. |
init_textpos | Sets column and line numbers to arbitrary values. |
free_textpos | Sets pos to textpos_FREE. |
query | |
column_textpos | Returns the current column number beginning from 0. |
line_textpos | Returns the current line number beginning from 1. |
prevlastcolumn_textpos | Returns the column number of the last character of the previous line (number). |
change | |
addcolumn_textpos | Adds increment to the column number. |
incrcolumn_textpos | Increments the column number. |
incrline_textpos | Increments the line number. |
inline implementation | |
textpos_t | |
addcolumn_textpos | Implements textpos_t.addcolumn_textpos. |
column_textpos | Implements textpos_t.column_textpos. |
free_textpos | Implements textpos_t.free_textpos. |
init_textpos | Implements textpos_t.init_textpos. |
line_textpos | Implements textpos_t.line_textpos. |
incrcolumn_textpos | Implements textpos_t.incrcolumn_textpos. |
incrline_textpos | Implements textpos_t.incrline_textpos. |
prevlastcolumn_textpos | Implements textpos_t.prevlastcolumn_textpos. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2013 Jörg Seebohn
Header file TextPosition.
Implementation file TextPosition impl.
typedef struct textpos_t textpos_t
Export textpos_t into global namespace.
test | |
unittest_string_textpos | Test textpos_t functionality. |
int unittest_string_textpos( void )
Test textpos_t functionality.
struct textpos_t
Describes position in text as column and line number. The first line has the line number 1 and the beginning of the text or the beginning of a new line has the column number 0. After reading a newline ‘\n’ the column number is reset to 0 and the line number is incremented. Reading another character increments the column number but does not change the line number. A text reader should call the functions
column | Column number of the last read character. |
line | Line number of the next unread character. |
prevlastcolumn | Column number of the last character on the previous line. |
lifetime | |
textpos_INIT | Static initializer. |
textpos_FREE | Static initializer. |
init_textpos | Sets column and line numbers to arbitrary values. |
free_textpos | Sets pos to textpos_FREE. |
query | |
column_textpos | Returns the current column number beginning from 0. |
line_textpos | Returns the current line number beginning from 1. |
prevlastcolumn_textpos | Returns the column number of the last character of the previous line (number). |
change | |
addcolumn_textpos | Adds increment to the column number. |
incrcolumn_textpos | Increments the column number. |
incrline_textpos | Increments the line number. |
size_t prevlastcolumn
Column number of the last character on the previous line. This value is a copy of column before it is set to 0 in function incrline_textpos.
void free_textpos( textpos_t * txtpos )
Sets pos to textpos_FREE.
textpos_t | |
addcolumn_textpos | Implements textpos_t.addcolumn_textpos. |
column_textpos | Implements textpos_t.column_textpos. |
free_textpos | Implements textpos_t.free_textpos. |
init_textpos | Implements textpos_t.init_textpos. |
line_textpos | Implements textpos_t.line_textpos. |
incrcolumn_textpos | Implements textpos_t.incrcolumn_textpos. |
incrline_textpos | Implements textpos_t.incrline_textpos. |
prevlastcolumn_textpos | Implements textpos_t.prevlastcolumn_textpos. |
#define addcolumn_textpos( txtpos, increment ) ((txtpos)->column += (increment))
Implements textpos_t.addcolumn_textpos.
#define column_textpos( txtpos ) ((txtpos)->column)
Implements textpos_t.column_textpos.
#define free_textpos( txtpos ) ((void)(*(txtpos) = (textpos_t)textpos_FREE))
Implements textpos_t.free_textpos.
#define init_textpos( txtpos, colnr, linenr ) ((void)(*(txtpos) = (textpos_t) { colnr, linenr, 0 }))
Implements textpos_t.init_textpos.
#define line_textpos( txtpos ) ((txtpos)->line)
Implements textpos_t.line_textpos.
#define incrcolumn_textpos( txtpos ) ((void)(++(txtpos)->column))
Implements textpos_t.incrcolumn_textpos.
#define incrline_textpos( txtpos ) do { textpos_t * _tpos = (txtpos) ; _tpos->prevlastcolumn = _tpos->column ; _tpos->column = 0 ; ++ _tpos->line ; } while (0)
Implements textpos_t.incrline_textpos.
#define prevlastcolumn_textpos( txtpos ) ((txtpos)->prevlastcolumn)
Implements textpos_t.prevlastcolumn_textpos.
Describes position in text as column and line number.
struct textpos_t
Export textpos_t into global namespace.
typedef struct textpos_t textpos_t
Test textpos_t functionality.
int unittest_string_textpos( void )
Column number of the last read character.
size_t column
Line number of the next unread character.
size_t line
Column number of the last character on the previous line.
size_t prevlastcolumn
Static initializer.
#define textpos_INIT { 0, 1, 0 }
Static initializer.
#define textpos_FREE { 0, 0, 0 }
Sets column and line numbers to arbitrary values.
void init_textpos( /*out*/textpos_t * txtpos, size_t colnr, size_t linenr )
Sets pos to textpos_FREE.
void free_textpos( textpos_t * txtpos )
Returns the current column number beginning from 0.
size_t column_textpos( const textpos_t * txtpos )
Returns the current line number beginning from 1.
size_t line_textpos( const textpos_t * txtpos )
Returns the column number of the last character of the previous line (number).
size_t prevlastcolumn_textpos( const textpos_t * txtpos )
Adds increment to the column number.
size_t addcolumn_textpos( textpos_t * txtpos, size_t increment )
Increments the column number.
void incrcolumn_textpos( textpos_t * txtpos )
Increments the line number.
void incrline_textpos( textpos_t * txtpos )
Implements textpos_t.addcolumn_textpos.
#define addcolumn_textpos( txtpos, increment ) ((txtpos)->column += (increment))
Implements textpos_t.column_textpos.
#define column_textpos( txtpos ) ((txtpos)->column)
Implements textpos_t.free_textpos.
#define free_textpos( txtpos ) ((void)(*(txtpos) = (textpos_t)textpos_FREE))
Implements textpos_t.init_textpos.
#define init_textpos( txtpos, colnr, linenr ) ((void)(*(txtpos) = (textpos_t) { colnr, linenr, 0 }))
Implements textpos_t.line_textpos.
#define line_textpos( txtpos ) ((txtpos)->line)
Implements textpos_t.incrcolumn_textpos.
#define incrcolumn_textpos( txtpos ) ((void)(++(txtpos)->column))
Implements textpos_t.incrline_textpos.
#define incrline_textpos( txtpos ) do { textpos_t * _tpos = (txtpos) ; _tpos->prevlastcolumn = _tpos->column ; _tpos->column = 0 ; ++ _tpos->line ; } while (0)
Implements textpos_t.prevlastcolumn_textpos.
#define prevlastcolumn_textpos( txtpos ) ((txtpos)->prevlastcolumn)