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