Fossil SCM

Minor stylistic changes to the comment formatter.

drh 2018-11-28 23:43 comment-formatter-utf8
Commit cc9c422d8325bb0af5c3cf533f7a4cc1137094c444441757bf9ed59229e043f9
1 file changed +12 -9
+12 -9
--- src/comformat.c
+++ src/comformat.c
@@ -2,11 +2,11 @@
22
** Copyright (c) 2007 D. Richard Hipp
33
**
44
** This program is free software; you can redistribute it and/or
55
** modify it under the terms of the Simplified BSD License (also
66
** known as the "2-Clause License" or "FreeBSD License".)
7
-
7
+**
88
** This program is distributed in the hope that it will be useful,
99
** but without any warranty; without even the implied warranty of
1010
** merchantability or fitness for a particular purpose.
1111
**
1212
** Author contact information:
@@ -152,18 +152,17 @@
152152
** sequences, respectively, the other invalid lead bytes 0xF8 to 0xFF are
153153
** treated as invalid 1-byte sequences (as lone trail bytes).
154154
** Combining characters and East Asian Wide and Fullwidth characters are counted
155155
** as one, so this function does not calculate the effective "display width".
156156
*/
157
-int strlen_utf8(const char *zString, int lengthBytes)
158
-{
157
+int strlen_utf8(const char *zString, int lengthBytes){
158
+ int i; /* Counted bytes. */
159
+ int lengthUTF8; /* Counted UTF-8 sequences. */
159160
#if 0
160161
assert( lengthBytes>=0 );
161162
#endif
162
- int i; /* Counted bytes. */
163
- int lengthUTF8; /* Counted UTF-8 sequences. */
164
- for( i=0, lengthUTF8=0; i<lengthBytes; i++, lengthUTF8++ ){
163
+ for(i=0, lengthUTF8=0; i<lengthBytes; i++, lengthUTF8++){
165164
char c = zString[i];
166165
int cchUTF8=1; /* Code units consumed. */
167166
int maxUTF8=1; /* Expected sequence length. */
168167
if( (c&0xe0)==0xc0 )maxUTF8=2; /* UTF-8 lead byte 110vvvvv */
169168
else if( (c&0xf0)==0xe0 )maxUTF8=3; /* UTF-8 lead byte 1110vvvv */
@@ -227,20 +226,24 @@
227226
if( lineChars<=0 ) return;
228227
#if 0
229228
assert( indent<sizeof(zBuf)-5 ); /* See following comments to explain */
230229
assert( origIndent<sizeof(zBuf)-5 ); /* these limits. */
231230
#endif
232
- if( indent>sizeof(zBuf)-6 ) /* Limit initial indent to fit output buffer. */
231
+ if( indent>sizeof(zBuf)-6 ){
232
+ /* Limit initial indent to fit output buffer. */
233233
indent = sizeof(zBuf)-6;
234
+ }
234235
comment_calc_indent(zLine, indent, trimCrLf, trimSpace, &index);
235236
if( indent>0 ){
236
- for( i=0; i<indent; i++ ){
237
+ for(i=0; i<indent; i++){
237238
zBuf[iBuf++] = ' ';
238239
}
239240
}
240
- if( origIndent>sizeof(zBuf)-6 ) /* Limit line indent to fit output buffer. */
241
+ if( origIndent>sizeof(zBuf)-6 ){
242
+ /* Limit line indent to fit output buffer. */
241243
origIndent = sizeof(zBuf)-6;
244
+ }
242245
maxChars = lineChars;
243246
for(;;){
244247
int useChars = 1;
245248
char c = zLine[index];
246249
/* Flush the output buffer if there's no space left for at least one more
247250
--- src/comformat.c
+++ src/comformat.c
@@ -2,11 +2,11 @@
2 ** Copyright (c) 2007 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
8 ** This program is distributed in the hope that it will be useful,
9 ** but without any warranty; without even the implied warranty of
10 ** merchantability or fitness for a particular purpose.
11 **
12 ** Author contact information:
@@ -152,18 +152,17 @@
152 ** sequences, respectively, the other invalid lead bytes 0xF8 to 0xFF are
153 ** treated as invalid 1-byte sequences (as lone trail bytes).
154 ** Combining characters and East Asian Wide and Fullwidth characters are counted
155 ** as one, so this function does not calculate the effective "display width".
156 */
157 int strlen_utf8(const char *zString, int lengthBytes)
158 {
 
159 #if 0
160 assert( lengthBytes>=0 );
161 #endif
162 int i; /* Counted bytes. */
163 int lengthUTF8; /* Counted UTF-8 sequences. */
164 for( i=0, lengthUTF8=0; i<lengthBytes; i++, lengthUTF8++ ){
165 char c = zString[i];
166 int cchUTF8=1; /* Code units consumed. */
167 int maxUTF8=1; /* Expected sequence length. */
168 if( (c&0xe0)==0xc0 )maxUTF8=2; /* UTF-8 lead byte 110vvvvv */
169 else if( (c&0xf0)==0xe0 )maxUTF8=3; /* UTF-8 lead byte 1110vvvv */
@@ -227,20 +226,24 @@
227 if( lineChars<=0 ) return;
228 #if 0
229 assert( indent<sizeof(zBuf)-5 ); /* See following comments to explain */
230 assert( origIndent<sizeof(zBuf)-5 ); /* these limits. */
231 #endif
232 if( indent>sizeof(zBuf)-6 ) /* Limit initial indent to fit output buffer. */
 
233 indent = sizeof(zBuf)-6;
 
234 comment_calc_indent(zLine, indent, trimCrLf, trimSpace, &index);
235 if( indent>0 ){
236 for( i=0; i<indent; i++ ){
237 zBuf[iBuf++] = ' ';
238 }
239 }
240 if( origIndent>sizeof(zBuf)-6 ) /* Limit line indent to fit output buffer. */
 
241 origIndent = sizeof(zBuf)-6;
 
242 maxChars = lineChars;
243 for(;;){
244 int useChars = 1;
245 char c = zLine[index];
246 /* Flush the output buffer if there's no space left for at least one more
247
--- src/comformat.c
+++ src/comformat.c
@@ -2,11 +2,11 @@
2 ** Copyright (c) 2007 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7 **
8 ** This program is distributed in the hope that it will be useful,
9 ** but without any warranty; without even the implied warranty of
10 ** merchantability or fitness for a particular purpose.
11 **
12 ** Author contact information:
@@ -152,18 +152,17 @@
152 ** sequences, respectively, the other invalid lead bytes 0xF8 to 0xFF are
153 ** treated as invalid 1-byte sequences (as lone trail bytes).
154 ** Combining characters and East Asian Wide and Fullwidth characters are counted
155 ** as one, so this function does not calculate the effective "display width".
156 */
157 int strlen_utf8(const char *zString, int lengthBytes){
158 int i; /* Counted bytes. */
159 int lengthUTF8; /* Counted UTF-8 sequences. */
160 #if 0
161 assert( lengthBytes>=0 );
162 #endif
163 for(i=0, lengthUTF8=0; i<lengthBytes; i++, lengthUTF8++){
 
 
164 char c = zString[i];
165 int cchUTF8=1; /* Code units consumed. */
166 int maxUTF8=1; /* Expected sequence length. */
167 if( (c&0xe0)==0xc0 )maxUTF8=2; /* UTF-8 lead byte 110vvvvv */
168 else if( (c&0xf0)==0xe0 )maxUTF8=3; /* UTF-8 lead byte 1110vvvv */
@@ -227,20 +226,24 @@
226 if( lineChars<=0 ) return;
227 #if 0
228 assert( indent<sizeof(zBuf)-5 ); /* See following comments to explain */
229 assert( origIndent<sizeof(zBuf)-5 ); /* these limits. */
230 #endif
231 if( indent>sizeof(zBuf)-6 ){
232 /* Limit initial indent to fit output buffer. */
233 indent = sizeof(zBuf)-6;
234 }
235 comment_calc_indent(zLine, indent, trimCrLf, trimSpace, &index);
236 if( indent>0 ){
237 for(i=0; i<indent; i++){
238 zBuf[iBuf++] = ' ';
239 }
240 }
241 if( origIndent>sizeof(zBuf)-6 ){
242 /* Limit line indent to fit output buffer. */
243 origIndent = sizeof(zBuf)-6;
244 }
245 maxChars = lineChars;
246 for(;;){
247 int useChars = 1;
248 char c = zLine[index];
249 /* Flush the output buffer if there's no space left for at least one more
250

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button