| 114 | } |
| 115 | |
| 116 | int m_vsnprintf(char *buf, size_t maxLen, const char *fmt, va_list args) |
| 117 | { |
| 118 | size_t size = 0; |
| 119 | auto add = [&](char c) { |
| 120 | if (++size < maxLen) *buf++ = c; |
| 121 | }; |
| 122 | |
| 123 | while (*fmt) { |
| 124 | // copy verbatim text |
| 125 | if (*fmt != '%') { |
| 126 | add(*fmt++); |
| 127 | continue; |
| 128 | } |
| 129 | fmt++; |
| 130 | |
| 131 | const char* s; // source for string copy |
| 132 | char tempNum[40]; // buffer for number conversion |
| 133 | |
| 134 | // reset attributes to defaults |
| 135 | bool minus = 0; |
| 136 | uint8_t ubase = 0; |
| 137 | int8_t precision = -1; |
| 138 | int8_t width = 0; |
| 139 | char pad = ' '; |
| 140 | uint8_t length = 0; |
| 141 | bool upcase = false; |
| 142 | |
| 143 | while (char f = *fmt) { |
| 144 | if (f == '-') minus = 1; |
| 145 | else if (f == '+') ; // ignored |
| 146 | else if (f == ' ') ; // ignored |
| 147 | else if (f == '#') ; // ignored |
| 148 | else break; |
| 149 | fmt++; |
| 150 | } |
| 151 | |
| 152 | // process padding |
| 153 | if (*fmt == '0') { |
| 154 | pad = '0'; |
| 155 | fmt++; |
| 156 | } |
| 157 | |
| 158 | // process width ('*' is not supported yet) |
| 159 | if ( is_digit(*fmt) ) { |
| 160 | width = skip_atoi(&fmt); |
| 161 | } |
| 162 | |
| 163 | // process precision |
| 164 | if( *fmt == '.' ) { |
| 165 | fmt++; |
| 166 | if ( is_digit(*fmt) ) precision = skip_atoi(&fmt); |
| 167 | } |
| 168 | |
| 169 | // while (*fmt == 'l' || *fmt == 'h' || *fmt == 'L') fmt++; |
| 170 | |
| 171 | // process length |
| 172 | do { |
| 173 | if ( *fmt == 'l' ) { |
no test coverage detected