cprintf.cc (7811:a8fc35183c10) | cprintf.cc (9331:6630b3ffe7c0) |
---|---|
1/* 2 * Copyright (c) 2002-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 55 unchanged lines hidden (view full) --- 64{ 65 fmt.clear(); 66 67 size_t len; 68 69 while (*ptr) { 70 switch (*ptr) { 71 case '%': | 1/* 2 * Copyright (c) 2002-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 55 unchanged lines hidden (view full) --- 64{ 65 fmt.clear(); 66 67 size_t len; 68 69 while (*ptr) { 70 switch (*ptr) { 71 case '%': |
72 if (ptr[1] != '%') 73 goto processing; 74 | 72 if (ptr[1] != '%') { 73 process_flag(); 74 return; 75 } |
75 stream.put('%'); 76 ptr += 2; 77 break; 78 79 case '\n': 80 stream << endl; 81 ++ptr; 82 break; --- 5 unchanged lines hidden (view full) --- 88 89 default: 90 len = strcspn(ptr, "%\n\r\0"); 91 stream.write(ptr, len); 92 ptr += len; 93 break; 94 } 95 } | 76 stream.put('%'); 77 ptr += 2; 78 break; 79 80 case '\n': 81 stream << endl; 82 ++ptr; 83 break; --- 5 unchanged lines hidden (view full) --- 89 90 default: 91 len = strcspn(ptr, "%\n\r\0"); 92 stream.write(ptr, len); 93 ptr += len; 94 break; 95 } 96 } |
97} |
|
96 | 98 |
97 return; 98 99 processing: | 99void 100Print::process_flag() 101{ |
100 bool done = false; 101 bool end_number = false; 102 bool have_precision = false; 103 int number = 0; 104 105 stream.fill(' '); 106 stream.flags((ios::fmtflags)0); 107 --- 135 unchanged lines hidden (view full) --- 243 if (have_precision) 244 fmt.precision = number; 245 else 246 fmt.width = number; 247 248 end_number = false; 249 number = 0; 250 } | 102 bool done = false; 103 bool end_number = false; 104 bool have_precision = false; 105 int number = 0; 106 107 stream.fill(' '); 108 stream.flags((ios::fmtflags)0); 109 --- 135 unchanged lines hidden (view full) --- 245 if (have_precision) 246 fmt.precision = number; 247 else 248 fmt.width = number; 249 250 end_number = false; 251 number = 0; 252 } |
251 } | |
252 | 253 |
254 if (done) { 255 if ((fmt.format == Format::integer) && have_precision) { 256 // specified a . but not a float, set width 257 fmt.width = fmt.precision; 258 // precision requries digits for width, must fill with 0 259 fmt.fill_zero = true; 260 } else if ((fmt.format == Format::floating) && !have_precision && 261 fmt.fill_zero) { 262 // ambiguous case, matching printf 263 fmt.precision = fmt.width; 264 } 265 } 266 } // end while 267 |
|
253 ++ptr; 254} 255 256void 257Print::end_args() 258{ 259 size_t len; 260 --- 34 unchanged lines hidden --- | 268 ++ptr; 269} 270 271void 272Print::end_args() 273{ 274 size_t len; 275 --- 34 unchanged lines hidden --- |