/src/lib/io/filesystem/path_name/unix_directory_notation.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 44 code · 8 blank · 25 comment · 5 complexity · fdf799ebbe282222500b4b25839e2aa4 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class UNIX_DIRECTORY_NOTATION
  5. -- The Unix like file path notation looks like:
  6. -- /LibertyEiffel/sys/system.se
  7. inherit
  8. PATH_NAME_NOTATION
  9. feature {ANY}
  10. is_current_directory (path: STRING): BOOLEAN
  11. do
  12. if path.compare(once ".") = 0 or else path.compare(once "./") = 0 then
  13. Result := True
  14. elseif path.is_empty then
  15. elseif path.first /= '/' then
  16. Result := path.occurrences('.') + path.occurrences('/') = path.count and not path.has_substring(once "..")
  17. end
  18. end
  19. is_parent_directory (path: STRING): BOOLEAN
  20. local
  21. pos: INTEGER
  22. do
  23. if path.compare(once "..") = 0 or else path.compare(once "../") = 0 then
  24. Result := True
  25. elseif path.is_empty then
  26. elseif path.first /= '/' then
  27. Result := path.occurrences('.') + path.occurrences('/') = path.count and path.has_substring(once "..")
  28. if Result then
  29. pos := path.first_substring_index(once "..")
  30. Result := Result and path.substring_index(once "..", pos + 2) = 0
  31. end
  32. end
  33. end
  34. to_directory_path (path: STRING)
  35. do
  36. path.extend_unless('/')
  37. end
  38. feature {ANY}
  39. is_case_sensitive: BOOLEAN True
  40. feature {}
  41. tmp1: POSIX_PATH_NAME
  42. once
  43. create Result.make_empty
  44. end
  45. tmp2: POSIX_PATH_NAME
  46. once
  47. create Result.make_empty
  48. end
  49. end -- class UNIX_DIRECTORY_NOTATION
  50. --
  51. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  52. --
  53. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  54. -- of this software and associated documentation files (the "Software"), to deal
  55. -- in the Software without restriction, including without limitation the rights
  56. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  57. -- copies of the Software, and to permit persons to whom the Software is
  58. -- furnished to do so, subject to the following conditions:
  59. --
  60. -- The above copyright notice and this permission notice shall be included in
  61. -- all copies or substantial portions of the Software.
  62. --
  63. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  64. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  65. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  66. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  67. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  68. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  69. -- THE SOFTWARE.