| 14622 | } |
| 14623 | // Resolves . and .. elements in a path with directory names |
| 14624 | function normalizeStringPosix(path, allowAboveRoot) { |
| 14625 | var res = "" |
| 14626 | var lastSegmentLength = 0 |
| 14627 | var lastSlash = -1 |
| 14628 | var dots = 0 |
| 14629 | var code |
| 14630 | for (var i = 0; i <= path.length; ++i) { |
| 14631 | if (i < path.length) code = path.charCodeAt(i) |
| 14632 | else if (code === 47 /*/*/) break |
| 14633 | else code = 47 /*/*/ |
| 14634 | if (code === 47 /*/*/) { |
| 14635 | if (lastSlash === i - 1 || dots === 1) { |
| 14636 | // NOOP |
| 14637 | } else if (lastSlash !== i - 1 && dots === 2) { |
| 14638 | if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) { |
| 14639 | if (res.length > 2) { |
| 14640 | var lastSlashIndex = res.lastIndexOf("/") |
| 14641 | if (lastSlashIndex !== res.length - 1) { |
| 14642 | if (lastSlashIndex === -1) { |
| 14643 | res = "" |
| 14644 | lastSegmentLength = 0 |
| 14645 | } else { |
| 14646 | res = res.slice(0, lastSlashIndex) |
| 14647 | lastSegmentLength = res.length - 1 - res.lastIndexOf("/") |
| 14648 | } |
| 14649 | lastSlash = i |
| 14650 | dots = 0 |
| 14651 | continue |
| 14652 | } |
| 14653 | } else if (res.length === 2 || res.length === 1) { |
| 14654 | res = "" |
| 14655 | lastSegmentLength = 0 |
| 14656 | lastSlash = i |
| 14657 | dots = 0 |
| 14658 | continue |
| 14659 | } |
| 14660 | } |
| 14661 | if (allowAboveRoot) { |
| 14662 | if (res.length > 0) res += "/.." |
| 14663 | else res = ".." |
| 14664 | lastSegmentLength = 2 |
| 14665 | } |
| 14666 | } else { |
| 14667 | if (res.length > 0) res += "/" + path.slice(lastSlash + 1, i) |
| 14668 | else res = path.slice(lastSlash + 1, i) |
| 14669 | lastSegmentLength = i - lastSlash - 1 |
| 14670 | } |
| 14671 | lastSlash = i |
| 14672 | dots = 0 |
| 14673 | } else if (code === 46 /*.*/ && dots !== -1) { |
| 14674 | ++dots |
| 14675 | } else { |
| 14676 | dots = -1 |
| 14677 | } |
| 14678 | } |
| 14679 | return res |
| 14680 | } |
| 14681 | function _posixFormat(sep, pathObject) { |