479 src, len, 1); |
480 src, len, 1); |
480 } |
481 } |
481 |
482 |
482 static const Py_ssize_t maxstorepathlen = 120; |
483 static const Py_ssize_t maxstorepathlen = 120; |
483 |
484 |
|
485 static Py_ssize_t _lowerencode(char *dest, size_t destsize, |
|
486 const char *src, Py_ssize_t len) |
|
487 { |
|
488 static const uint32_t onebyte[8] = { |
|
489 1, 0x2bfffbfb, 0xe8000001, 0x2fffffff |
|
490 }; |
|
491 |
|
492 static const uint32_t lower[8] = { 0, 0, 0x7fffffe }; |
|
493 |
|
494 Py_ssize_t i, destlen = 0; |
|
495 |
|
496 for (i = 0; i < len; i++) { |
|
497 if (inset(onebyte, src[i])) |
|
498 charcopy(dest, &destlen, destsize, src[i]); |
|
499 else if (inset(lower, src[i])) |
|
500 charcopy(dest, &destlen, destsize, src[i] + 32); |
|
501 else |
|
502 escape3(dest, &destlen, destsize, src[i]); |
|
503 } |
|
504 |
|
505 return destlen; |
|
506 } |
|
507 |
|
508 PyObject *lowerencode(PyObject *self, PyObject *args) |
|
509 { |
|
510 char *path; |
|
511 Py_ssize_t len, newlen; |
|
512 PyObject *ret; |
|
513 |
|
514 if (!PyArg_ParseTuple(args, "s#:lowerencode", &path, &len)) |
|
515 return NULL; |
|
516 |
|
517 newlen = _lowerencode(NULL, 0, path, len); |
|
518 ret = PyString_FromStringAndSize(NULL, newlen); |
|
519 if (ret) |
|
520 newlen = _lowerencode(PyString_AS_STRING(ret), newlen, |
|
521 path, len); |
|
522 |
|
523 return ret; |
|
524 } |
|
525 |
484 /* |
526 /* |
485 * We currently implement only basic encoding. |
527 * We currently implement only basic encoding. |
486 * |
528 * |
487 * If a name is too long to encode due to Windows path name limits, |
529 * If a name is too long to encode due to Windows path name limits, |
488 * this function returns None. |
530 * this function returns None. |