Differences From Artifact [02ef45c9df]:
- File
src/OFString.m
— part of check-in
[34fe205b84]
at
2017-11-12 18:27:56
on branch trunk
— OFFileManager: Major API redesign
This removes all query methods and replaces them by a single one that
returns a dictionary. Not only does this allow querying multiple
attributes at once, it is also more extensible, as the previous
attributes were specific to file URLs. (user: js, size: 67076) [annotate] [blame] [check-ins using]
To Artifact [0ce80cb81c]:
- File src/OFString.m — part of check-in [4f2b0f0847] at 2017-11-13 21:56:37 on branch trunk — Add -[OFString indexOfCharacterFromSet:] (user: js, size: 68781) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
29 30 31 32 33 34 35 | # include <xlocale.h> #endif #import "OFString.h" #import "OFString_UTF8.h" #import "OFString_UTF8+Private.h" #import "OFArray.h" | > | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # include <xlocale.h> #endif #import "OFString.h" #import "OFString_UTF8.h" #import "OFString_UTF8+Private.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" #import "OFLocalization.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFURL.h" #import "OFXMLElement.h" |
︙ | ︙ | |||
1848 1849 1850 1851 1852 1853 1854 | if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); searchCharacters = [string characters]; | < | | 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 | if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); searchCharacters = [string characters]; if ((characters = malloc(range.length * sizeof(of_unichar_t))) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: range.length * sizeof(of_unichar_t)]; @try { [self getCharacters: characters inRange: range]; |
︙ | ︙ | |||
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 | free(characters); } objc_autoreleasePoolPop(pool); return of_range(OF_NOT_FOUND, 0); } - (bool)containsString: (OFString *)string { void *pool; const of_unichar_t *characters, *searchCharacters; size_t length, searchLength; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 | free(characters); } objc_autoreleasePoolPop(pool); return of_range(OF_NOT_FOUND, 0); } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet { return [self indexOfCharacterFromSet: characterSet options: 0 range: of_range(0, [self length])]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (int)options { return [self indexOfCharacterFromSet: characterSet options: options range: of_range(0, [self length])]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (int)options range: (of_range_t)range { bool (*characterIsMember)(id, SEL, of_unichar_t) = (bool (*)(id, SEL, of_unichar_t))[characterSet methodForSelector: @selector(characterIsMember:)]; of_unichar_t *characters; if (range.length == 0) return OF_NOT_FOUND; if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exception]; if ((characters = malloc(range.length * sizeof(of_unichar_t))) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: range.length * sizeof(of_unichar_t)]; @try { [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { for (size_t i = range.length - 1;; i--) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i < range.length; i++) if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; } } @finally { free(characters); } return OF_NOT_FOUND; } - (bool)containsString: (OFString *)string { void *pool; const of_unichar_t *characters, *searchCharacters; size_t length, searchLength; |
︙ | ︙ |