@@ -203,16 +203,20 @@ uint8_t SdFile::dirEntry(dir_t* dir) {
203
203
\param[out] name A 13 byte char array for the formatted name.
204
204
*/
205
205
void SdFile::dirName (const dir_t & dir, char * name) {
206
- uint8_t j = 0 ;
207
- for (uint8_t i = 0 ; i < 11 ; i++) {
208
- if (dir.name [i] == ' ' ) {
209
- continue ;
210
- }
206
+ uint8_t i = 0 , j = 0 ;
207
+ // unescape first character
208
+ if ((uint8_t ) dir.name [i] == DIR_NAME_0XE5) {
209
+ name[j++] = 0xE5 ;
210
+ i++;
211
+ }
212
+ for (; i < 11 ; i++) {
211
213
if (i == 8 ) {
214
+ while (j > 0 && name[j-1 ] == ' ' ) j--;
212
215
name[j++] = ' .' ;
213
216
}
214
217
name[j++] = dir.name [i];
215
218
}
219
+ while (name[j-1 ] == ' ' ) j--;
216
220
name[j] = 0 ;
217
221
}
218
222
// ------------------------------------------------------------------------------
@@ -288,10 +292,12 @@ uint8_t SdFile::make83Name(const char* str, uint8_t* name) {
288
292
uint8_t n = 7 ; // max index for part before dot
289
293
uint8_t i = 0 ;
290
294
// blank fill name and extension
291
- while (i < 11 ) {
292
- name[i++] = ' ' ;
295
+ memset (name, ' ' , 11 );
296
+ // escape first character
297
+ if ((uint8_t ) *str == 0xE5 ) {
298
+ name[i++] = DIR_NAME_0XE5;
299
+ str++;
293
300
}
294
- i = 0 ;
295
301
while ((c = *str++) != ' \0 ' ) {
296
302
if (c == ' .' ) {
297
303
if (n == 10 ) {
@@ -301,16 +307,12 @@ uint8_t SdFile::make83Name(const char* str, uint8_t* name) {
301
307
i = 8 ; // place for extension
302
308
} else {
303
309
// illegal FAT characters
304
- uint8_t b;
305
310
#if defined(__AVR__)
306
- PGM_P p = PSTR (" |<>:+=?/[];,*\"\\ " );
307
- while ((b = pgm_read_byte (p++))) if (b == c) {
311
+ if (strchr_P (PSTR (" |<>:+=?/[];,*\"\\ " ), c)) {
308
312
return false ;
309
313
}
310
- #elif defined(__arm__)
311
- const uint8_t valid[] = " |<>:+=?/[];,*\"\\ " ;
312
- const uint8_t *p = valid;
313
- while ((b = *p++)) if (b == c) {
314
+ #else
315
+ if (strchr (" |<>:+=?/[];,*\"\\ " , c)) {
314
316
return false ;
315
317
}
316
318
#endif
@@ -323,7 +325,7 @@ uint8_t SdFile::make83Name(const char* str, uint8_t* name) {
323
325
}
324
326
}
325
327
// must have a file name, extension is optional
326
- return name[ 0 ] != ' ' ;
328
+ return i > 0 ;
327
329
}
328
330
// ------------------------------------------------------------------------------
329
331
/* * Make a new directory.
@@ -690,11 +692,13 @@ uint8_t SdFile::openRoot(SdVolume* vol) {
690
692
\param[in] width Blank fill name if length is less than \a width.
691
693
*/
692
694
void SdFile::printDirName (const dir_t & dir, uint8_t width) {
693
- uint8_t w = 0 ;
694
- for (uint8_t i = 0 ; i < 11 ; i++) {
695
- if (dir.name [i] == ' ' ) {
696
- continue ;
697
- }
695
+ uint8_t i = 0 , w = 0 ;
696
+ // unescape first character
697
+ if ((uint8_t ) dir.name [i] == DIR_NAME_0XE5) {
698
+ Serial.write (0xE5 );
699
+ i++; w++;
700
+ }
701
+ for (; i < 11 ; i++) {
698
702
if (i == 8 ) {
699
703
Serial.print (' .' );
700
704
w++;
0 commit comments