MCPcopy Create free account
hub / github.com/apache/cloudberry / extract_field

Function extract_field

contrib/formatter_fixedwidth/fixedwidth.c:90–129  ·  view source on GitHub ↗

* extract_field * * extract a field value from a character string 'data_cursor'. If we * preserve blanks, then the entire field_total_length is extracted. * Otherwise, we extract all bytes except the trailing blanks. The field * value is then stored inside 'output'. */

Source from the content-addressed store, hash-verified

88 * value is then stored inside 'output'.
89 */
90static void
91extract_field(char *data_cursor, int field_total_length, bool preserve_blanks, StringInfo output)
92{
93 int actual_length;
94
95 /*
96 * the actual length of the string we will restore into the database depends whether
97 * we preserve_blanks or not.
98 */
99 if (preserve_blanks)
100 {
101 actual_length = field_total_length;
102 }
103 else
104 {
105 /*
106 * assume all field characters are blanks
107 */
108 char *tail = data_cursor + field_total_length - 1;
109 actual_length = 0;
110
111 while (tail != data_cursor)
112 {
113 if (*tail != ' ')
114 {
115 actual_length = tail - data_cursor + 1;
116 break;
117 }
118 tail--;
119 }
120
121 if ( (tail == data_cursor) && (*data_cursor != ' ') )
122 {
123 actual_length = 1;
124 }
125 }
126
127 /* store the extracted field value */
128 appendBinaryStringInfo(output, data_cursor, actual_length);
129}
130
131static void
132reset_format_in_config(FormatConfig *format_config)

Callers 1

fixedwidth_inFunction · 0.85

Calls 1

appendBinaryStringInfoFunction · 0.85

Tested by

no test coverage detected