Differences From Artifact [f5bfcef342]:
- File src/OFString.m — part of check-in [374e1a1bfa] at 2021-01-02 22:04:26 on branch trunk — Update copyright (user: js, size: 67483) [annotate] [blame] [check-ins using] [more...]
To Artifact [cc999ec09b]:
- File
src/OFString.m
— part of check-in
[a0fd103a0b]
at
2021-03-07 02:36:04
on branch trunk
— Style change: Allow more than 1 argument per line
This is only migrating some places, others will be migrated as they are
touched. (user: js, size: 67153) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
347 348 349 350 351 352 353 | size_t length = self.length; for (size_t i = 0; i < length; i++) { of_unichar_t c = characters[i]; const char *const *page; if (c >= size) { | | < | < | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | size_t length = self.length; for (size_t i = 0; i < length; i++) { of_unichar_t c = characters[i]; const char *const *page; if (c >= size) { [ret appendCharacters: &c length: 1]; continue; } page = table[c >> 8]; if (page != NULL && page[c & 0xFF] != NULL) [ret appendUTF8String: page[c & 0xFF]]; else [ret appendCharacters: &c length: 1]; } objc_autoreleasePoolPop(pool); return ret; } #endif |
︙ | ︙ | |||
964 965 966 967 968 969 970 | - (instancetype)initWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); | | < | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | - (instancetype)initWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); ret = [self initWithFormat: format arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments |
︙ | ︙ | |||
1020 1021 1022 1023 1024 1025 1026 | * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; tmp = of_alloc((size_t)fileSize + 1, 1); @try { | | < | 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; tmp = of_alloc((size_t)fileSize + 1, 1); @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp exactLength: (size_t)fileSize]; } @catch (id e) { free(tmp); @throw e; } @finally { |
︙ | ︙ | |||
1441 1442 1443 1444 1445 1446 1447 | free(cString); @throw e; } } - (const char *)cStringWithEncoding: (of_string_encoding_t)encoding { | | < | < | 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | free(cString); @throw e; } } - (const char *)cStringWithEncoding: (of_string_encoding_t)encoding { return [self of_cStringWithEncoding: encoding lossy: false]; } - (const char *)lossyCStringWithEncoding: (of_string_encoding_t)encoding { return [self of_cStringWithEncoding: encoding lossy: true]; } - (const char *)UTF8String { return [self cStringWithEncoding: OF_STRING_ENCODING_UTF_8]; } |
︙ | ︙ | |||
1718 1719 1720 1721 1722 1723 1724 | objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { | | < | < | < | < | < | < | < | < | < | < | < | < | < | < | < | < | < | 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 | objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (int)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *)of_JSONRepresentationWithOptions: (int)options depth: (size_t)depth { OFMutableString *JSON = [[self mutableCopy] autorelease]; /* FIXME: This is slow! Write it in pure C! */ [JSON replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [JSON replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [JSON replaceOccurrencesOfString: @"\b" withString: @"\\b"]; [JSON replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [JSON replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [JSON replaceOccurrencesOfString: @"\t" withString: @"\\t"]; if (options & OF_JSON_REPRESENTATION_JSON5) { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"]; if (options & OF_JSON_REPRESENTATION_IDENTIFIER) { const char *cString = self.UTF8String; if ((!of_ascii_isalpha(cString[0]) && cString[0] != '_' && cString[0] != '$') || strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) { [JSON prependString: @"\""]; [JSON appendString: @"\""]; } } else { [JSON prependString: @"\""]; [JSON appendString: @"\""]; } } else { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [JSON prependString: @"\""]; [JSON appendString: @"\""]; } [JSON makeImmutable]; return JSON; } - (OFData *)messagePackRepresentation { OFMutableData *data; size_t length; length = self.UTF8StringLength; if (length <= 31) { uint8_t tmp = 0xA0 | ((uint8_t)length & 0x1F); data = [OFMutableData dataWithItemSize: 1 capacity: length + 1]; [data addItem: &tmp]; } else if (length <= UINT8_MAX) { uint8_t type = 0xD9; uint8_t tmp = (uint8_t)length; data = [OFMutableData dataWithItemSize: 1 capacity: length + 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (length <= UINT16_MAX) { uint8_t type = 0xDA; uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)length); data = [OFMutableData dataWithItemSize: 1 capacity: length + 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (length <= UINT32_MAX) { uint8_t type = 0xDB; uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)length); data = [OFMutableData dataWithItemSize: 1 capacity: length + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; [data addItems: self.UTF8String count: length]; return data; } - (of_range_t)rangeOfString: (OFString *)string { return [self rangeOfString: string |
︙ | ︙ | |||
1868 1869 1870 1871 1872 1873 1874 | pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; characters = of_alloc(range.length, sizeof(of_unichar_t)); @try { | | < | 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 | pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; characters = of_alloc(range.length, sizeof(of_unichar_t)); @try { [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t)) == 0) { objc_autoreleasePoolPop(pool); return of_range(range.location + i, |
︙ | ︙ | |||
1936 1937 1938 1939 1940 1941 1942 | return OF_NOT_FOUND; if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exception]; characters = of_alloc(range.length, sizeof(of_unichar_t)); @try { | | < | 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 | return OF_NOT_FOUND; if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exception]; characters = of_alloc(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; |
︙ | ︙ | |||
2040 2041 2042 2043 2044 2045 2046 | - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ... { OFString *ret; va_list arguments; va_start(arguments, format); | | < < < | | < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < | < | 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 | - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ... { OFString *ret; va_list arguments; va_start(arguments, format); ret = [self stringByAppendingFormat: format arguments: arguments]; va_end(arguments); return ret; } - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments { OFMutableString *new = [OFMutableString stringWithString: self]; [new appendFormat: format arguments: arguments]; [new makeImmutable]; return new; } - (OFString *)stringByPrependingString: (OFString *)string { OFMutableString *new = [[string mutableCopy] autorelease]; [new appendString: self]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (of_range_t)range { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement options: options range: range]; [new makeImmutable]; return new; } - (OFString *)uppercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new uppercase]; [new makeImmutable]; return new; } - (OFString *)lowercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new lowercase]; [new makeImmutable]; return new; } - (OFString *)capitalizedString { OFMutableString *new = [[self mutableCopy] autorelease]; [new capitalize]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingLeadingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteLeadingWhitespaces]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingTrailingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteTrailingWhitespaces]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingEnclosingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteEnclosingWhitespaces]; [new makeImmutable]; return new; } - (bool)hasPrefix: (OFString *)prefix { of_unichar_t *tmp; size_t prefixLength; bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; tmp = of_alloc(prefixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(of_unichar_t)) == 0); objc_autoreleasePoolPop(pool); } @finally { free(tmp); |
︙ | ︙ | |||
2229 2230 2231 2232 2233 2234 2235 | } return hasSuffix; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { | | < | 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 | } return hasSuffix; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { return [self componentsSeparatedByString: delimiter options: 0]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (int)options { void *pool; OFMutableArray *array; |
︙ | ︙ | |||
2599 2600 2601 2602 2603 2604 2605 | - (const of_unichar_t *)characters { size_t length = self.length; of_unichar_t *buffer; buffer = of_alloc(length, sizeof(of_unichar_t)); @try { | | < | 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 | - (const of_unichar_t *)characters { size_t length = self.length; of_unichar_t *buffer; buffer = of_alloc(length, sizeof(of_unichar_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; return [[OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(of_unichar_t) freeWhenDone: true] items]; } @catch (id e) { free(buffer); |
︙ | ︙ | |||
2701 2702 2703 2704 2705 2706 2707 | - (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { size_t length = self.length; of_char32_t *buffer; buffer = of_alloc(length + 1, sizeof(of_char32_t)); @try { | | < | 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 | - (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { size_t length = self.length; of_char32_t *buffer; buffer = of_alloc(length + 1, sizeof(of_char32_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; buffer[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) for (size_t i = 0; i < length; i++) buffer[i] = OF_BSWAP32(buffer[i]); return [[OFData dataWithItemsNoCopy: buffer |
︙ | ︙ | |||
2780 2781 2782 2783 2784 2785 2786 | } } #endif #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { | | < < | < | < | < | < | 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 | } } #endif #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { [self writeToFile: path encoding: OF_STRING_ENCODING_UTF_8]; } - (void)writeToFile: (OFString *)path encoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #endif - (void)writeToURL: (OFURL *)URL { [self writeToURL: URL encoding: OF_STRING_ENCODING_UTF_8]; } - (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFURLHandler *URLHandler; OFStream *stream; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; stream = [URLHandler openItemAtURL: URL mode: @"w"]; [stream writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { |
︙ | ︙ |