([^<]+?) *<(http.+?)><\/code>_+/g, '$1 ') // links get screwed up
136 | .replace(/<(http.+?)>/g, '$1 ') // more linking
137 | .replace(/\s+<\/a>/g, '') // more linking
138 | .replace(/\\\\ /g, '') // get rid of extraneous double-backslashes
139 | .replace(/\\ /g, '') // and extraneous single-backslashes
140 | .replace(/:<\/p>\n?\n?/, '') // leftovers from '::' on own line
141 | .replace(/
/g, ''); // add language class to pre/code blocks
142 |
143 | return html;
144 | }
145 |
146 | Twig.extendFilter('rst', convertComment);
147 |
148 | Twig.extendFilter('withSpaceAfter', function(value) {
149 | return (value) ? value + ' ' : '';
150 | });
151 |
152 | Twig.extendFilter('static', function(values) {
153 | return values.filter(function(val) {
154 | return isStatic(val);
155 | });
156 | })
157 |
158 | Twig.extendFilter('instance', function(values) {
159 | return values.filter(function(val) {
160 | return !isStatic(val);
161 | });
162 | })
163 |
164 | Twig.extendFilter('addSoftBreaks', function(value) {
165 | return value.replace(/([^(:]+?:)/g, '$1');
166 | });
167 |
168 | // ----------------------------------------------------------------------------
169 | // Output to files
170 |
171 | function outputHTML(path, template, obj, info) {
172 | info.root = urlPrefix;
173 | obj.root = urlPrefix;
174 |
175 | var yaml = buildYAML(info);
176 | var output = template.render(obj);
177 |
178 | mkdirp.sync(outputDir + path);
179 | fs.writeFileSync(outputDir + path + '/index.html', yaml + output);
180 | }
181 |
182 | function addLogo(svgData) {
183 | return svgData.replace(/(]+translate\([0-9.]+ ([0-9.]+)\)">)/,
184 | '$1\n\n' + svgLogo + '\n ');
185 |
186 | }
187 |
188 | function customizeGraph(svgData) {
189 | return svgData.replace(/[^<]+<\/title>/g, '') // get rid of titles
190 | .replace(/ xlink:title="[^"]+"/g, ' target="_top"') // and title attributes
191 | .replace(/]+>/g, '') // clear background
192 | .replace(/\/(type|protocol)\//g, urlPrefix + '/$1/') // add root url
193 | }
194 |
195 | function setMinimumWidth(svgData) {
196 | var match = /svg width=\"([^\"]+)pt\"/.exec(svgData),
197 | width = (match) ? match[1] : null;
198 |
199 | if (width && (width < 320)) {
200 | return svgData.replace(/(]+viewBox=\"\S+ \S+ )(\S+)/, '$01320$03320.0');
201 | } else {
202 | return svgData;
203 | }
204 | }
205 |
206 | function objectToYAML(obj) {
207 | var yaml = '---\n';
208 | for (key in obj) {
209 | yaml += key + ': "' + obj[key].replace('"', '"') + '"\n';
210 | }
211 | yaml += '---\n\n';
212 | return yaml;
213 | }
214 |
215 | function getWrapperForGraph(type) {
216 | var info = {
217 | layout: 'svg_wrapper',
218 | title: 'Inheritance Graph for ' + type.name,
219 | typename: type.name,
220 | };
221 |
222 | return objectToYAML(info);
223 | }
224 |
225 | function outputGraph(path, dot, type) {
226 | var dotFile = outputDir + path + '/index.dot';
227 | var svgFile = outputDir + path + '/index.svg';
228 |
229 | // output dot-file
230 | mkdirp.sync(outputDir + path);
231 | fs.writeFileSync(dotFile, dot);
232 |
233 | // create and write the SVG
234 | var svgData = execsyncs('cat ' + dotFile + ' | /usr/local/bin/dot -Tsvg');
235 | svgData = addLogo(customizeGraph(svgData));
236 | fs.writeFileSync(svgFile, svgData);
237 |
238 | // create an HTML wrapper
239 | fs.writeFileSync(outputDir + path + '/index.html', getWrapperForGraph(type));
240 | }
241 |
242 | function generateItemInfo(item) {
243 | function skipEmpty(el) {
244 | return ((el != '') && (el != undefined));
245 | }
246 |
247 | function getName(item) {
248 | return item.name;
249 | }
250 |
251 | // title will just be the name
252 | var name = item.name;
253 |
254 | // meta description
255 | var description = '';
256 | if (item.comment) {
257 | var i = item.comment.search(/[\n\r]/);
258 | var comment = i == -1 ? item.comment : item.comment.substring(0, i);
259 | description = convertComment(comment);
260 | }
261 | if (description == '') {
262 | description = 'Swift documentation for ' + item.kind + ' \'' + name + '\'.';
263 | } else {
264 | description = description.replace(/<\/p>[^]*/, '')
265 | .replace(/<[^>]+>/ig, '')
266 | .replace(/\\ /g, '')
267 | .replace(/\\\(/, '\\\\(')
268 | .replace(/\.$/, '');
269 | description = 'Swift documentation for \'' + name + '\': ' + description + '.';
270 | }
271 |
272 | // meta keywords
273 | var keywords = [name, item.kind, 'swift', 'documentation'];
274 | if (item.functions)
275 | keywords.push.call(keywords, item.functions.map(getName));
276 | if (item.properties)
277 | keywords.push.call(keywords, item.properties.map(getName));
278 | if (item.aliases)
279 | keywords.push.call(keywords, item.aliases.map(getName));
280 |
281 | return { title: name, description: description, keywords: keywords.unique().filter(skipEmpty).join(',') };
282 | }
283 |
284 | function collectLinks(list, initial, linker, prefix) {
285 | if (!prefix) prefix = '';
286 |
287 | return list.reduce(function (p, c) {
288 | if (c.inherited == true) return p;
289 | if (p[prefix + c.name]) return p;
290 | p[prefix + c.name] = linker(c);
291 | return p;
292 | }, initial);
293 | }
294 |
295 | function buildYAML(info) {
296 | // nothing to do here
297 | if (!info) return '';
298 |
299 | var yamlObject = { layout: (info.title == "Home") ? 'home' : 'default' };
300 | for (key in info) yamlObject[key] = info[key];
301 |
302 | // TODO: version number?
303 |
304 | return objectToYAML(yamlObject);
305 | }
306 |
307 | function build(context) {
308 | // prepare local data
309 | var typesAsArray = Object.keys(context.types)
310 | .sort()
311 | .map(function(el) { return context.types[el] });
312 | var typeArray = typesAsArray.filter(function (el) { return el.kind != 'protocol' });
313 | var protocolArray = typesAsArray.filter(function (el) { return el.kind == 'protocol' });
314 | var functionNames = context.functions.map(function(el) { return el.name; }).unique().sort();
315 | var linkData = {};
316 |
317 | // this returns a function that adds a set prefix to whatever's passed in
318 | // handy for prepending URL paths onto type and function names below
319 | var prefixer = function(prefix) {
320 | return function(item) {
321 | return prefix + (item.uniqueSignatureURL || item.name);
322 | };
323 | };
324 | var functionPrefixer = function(prefix) {
325 | return function(item) {
326 | return prefix + item.name;
327 | };
328 | };
329 |
330 | // home page
331 | outputHTML('', templates.index_home, {
332 | types: typeArray,
333 | protocols: protocolArray,
334 | operators: context.operators,
335 | functions: functionNames,
336 | }, pageInfo.home);
337 |
338 | // index pages
339 | outputHTML('protocol', templates.index_type, { items: protocolArray, path: 'protocol' }, pageInfo.index_protocol);
340 | outputHTML('type', templates.index_type, { items: typeArray, path: 'type' }, pageInfo.index_type);
341 | outputHTML('operator', templates.index_operator, { operators: context.operators }, pageInfo.index_operator);
342 | outputHTML('global', templates.index_global, { functions: functionNames }, pageInfo.index_global);
343 | outputHTML('func', templates.index_func, { functions: functionNames }, pageInfo.index_func);
344 |
345 | // types & protocols
346 | typesAsArray.forEach(function(el) {
347 | var info = generateItemInfo(el);
348 | var kind = (el.kind == 'protocol') ? el.kind : 'type';
349 |
350 | // get DOT for graphviz
351 | var dot = '';
352 | var hasHierarchy = false;
353 | if (outputGraphs) {
354 | dot = grapher.getTypeDOT(el.name, context);
355 | hasHierarchy = (dot.indexOf('->') != -1);
356 | }
357 |
358 | linkData = collectLinks(el.functions || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/func#func-'), el.name + '.')
359 | linkData = collectLinks(el.properties || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/prop#'), el.name + '.')
360 | linkData = collectLinks(el.cases || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/case#'), el.name + '.')
361 |
362 | if (el.imp) {
363 | for (var impKey in el.imp) {
364 | var imp = el.imp[impKey];
365 | linkData = collectLinks(imp.functions || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/func#func-' + impKey.urlify() + '-'), el.name + '.')
366 | linkData = collectLinks(imp.properties || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/prop#' + impKey.urlify() + '-'), el.name + '.')
367 | linkData = collectLinks(imp.cases || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/case#' + impKey.urlify() + '-'), el.name + '.')
368 | }
369 | }
370 |
371 | outputHTML('' + kind + '/' + el.name, templates.type, { type: el, hasHierarchy: hasHierarchy }, info);
372 |
373 | if (hasHierarchy)
374 | outputGraph('' + kind + '/' + el.name + '/hierarchy', dot, el);
375 | })
376 |
377 | // operators
378 | context.operators.forEach(function (el) {
379 | outputHTML('operator/' + el.slug, templates.operator, { operator: el }, {
380 | title: 'Operator: ' + el.name,
381 | description: 'Swift documentation for the \'' + el.name + '\' operator.',
382 | });
383 | });
384 |
385 | // functions
386 | functionNames.forEach(function (funcName) {
387 | var functions = context.functions.filter(function(el) { return el.name == funcName });
388 | var info = generateItemInfo(functions[0]);
389 | outputHTML('func/' + funcName, templates.func, { functions: functions }, info);
390 | });
391 |
392 | // type aliases
393 | outputHTML('global/alias', templates.alias_list, { aliases: context.aliases }, pageInfo.alias_list);
394 |
395 |
396 | // operators need to have names converted for URL safety
397 | linkData = collectLinks(context.operators, linkData, function (item) { return urlPrefix + '/operator/' + item.slug; });
398 |
399 | // functions, types, & protocols are all simple
400 | linkData = collectLinks(context.functions, linkData, functionPrefixer(urlPrefix + '/func/'));
401 | linkData = collectLinks(typeArray, linkData, prefixer(urlPrefix + '/type/'));
402 | linkData = collectLinks(protocolArray, linkData, prefixer(urlPrefix + '/protocol/'));
403 |
404 | // variables and type aliases have only a single page each
405 | linkData = collectLinks(context.aliases, linkData, function() { return urlPrefix + '/global/alias/' });
406 |
407 | // build and write JS link data
408 | var linkDataString = 'var linkdata = ' + JSON.stringify(linkData) + ';\n';
409 | mkdirp.sync(outputDir + 'assets/js' );
410 | fs.writeFile(outputDir + 'assets/js/swift-linkdata.js', linkDataString);
411 | }
412 |
413 | // ----------------------------------------------------------------------------
414 | // Export
415 |
416 | var Builder = function() { };
417 |
418 | Builder.prototype.build = build;
419 |
420 | Builder.prototype.setOutputDir = function(dir) {
421 | outputDir = appRoot + dir.replace(/\/$/, '') + '/';
422 | };
423 |
424 | Builder.prototype.setURLPrefix = function(prefix) {
425 | urlPrefix = prefix.replace(/\/$/, '');
426 | };
427 |
428 | Builder.prototype.setOutputGraphs = function(output) {
429 | outputGraphs = output;
430 | };
431 |
432 | module.exports = new Builder();
433 |
434 |
435 |
--------------------------------------------------------------------------------
/data/addenda/1.2/foundation.txt:
--------------------------------------------------------------------------------
1 | extension String.UTF16View.Index : RandomAccessIndexType {
2 |
3 | /// *[Foundation]* Construct from an integer offset.
4 | init(_ offset: Int)
5 |
6 | /// *[Foundation]* Return the minimum number of applications of `successor` or
7 | /// `predecessor` required to reach `other` from `self`.
8 | ///
9 | /// Complexity: O(1).
10 | func distanceTo(x: String.UTF16View.Index) -> Int
11 |
12 | /// *[Foundation]* Return `self` offset by `n` steps.
13 | ///
14 | /// :returns: If `n > 0`, the result of applying `successor` to
15 | /// `self` `n` times. If `n < 0`, the result of applying
16 | /// `predecessor` to `self` `-n` times. Otherwise, `self`.
17 | ///
18 | /// Complexity: O(1)
19 | func advancedBy(x: Int) -> String.UTF16View.Index
20 | }
21 |
22 | extension String {
23 |
24 | /// *[Foundation]* Returns an Array of the encodings string objects support
25 | /// in the application’s environment.
26 | static func availableStringEncodings() -> [NSStringEncoding]
27 |
28 | /// *[Foundation]* Returns the C-string encoding assumed for any method accepting
29 | /// a C string as an argument.
30 | static func defaultCStringEncoding() -> NSStringEncoding
31 |
32 | /// *[Foundation]* Returns a human-readable string giving the name of a given encoding.
33 | static func localizedNameOfStringEncoding(encoding: NSStringEncoding) -> String
34 |
35 | /// *[Foundation]* Returns a string created by using a given format string as a
36 | /// template into which the remaining argument values are substituted
37 | /// according to the user's default locale.
38 | static func localizedStringWithFormat(format: String, _ arguments: CVarArgType...) -> String
39 |
40 | /// *[Foundation]* Returns a string built from the strings in a given array
41 | /// by concatenating them with a path separator between each pair.
42 | static func pathWithComponents(components: [String]) -> String
43 |
44 | /// *[Foundation]* Produces a string created by reading data from the file at a
45 | /// given path interpreted using a given encoding.
46 | init?(contentsOfFile path: String, encoding enc: NSStringEncoding, error: NSErrorPointer = default)
47 |
48 | /// *[Foundation]* Produces a string created by reading data from the file at
49 | /// a given path and returns by reference the encoding used to
50 | /// interpret the file.
51 | init?(contentsOfFile path: String, usedEncoding: UnsafeMutablePointer = default, error: NSErrorPointer = default)
52 |
53 | /// *[Foundation]* Produces a string created by reading data from a given URL
54 | /// interpreted using a given encoding. Errors are written into the
55 | /// inout `error` argument.
56 | init?(contentsOfURL url: NSURL, encoding enc: NSStringEncoding, error: NSErrorPointer = default)
57 |
58 | /// *[Foundation]* Produces a string created by reading data from a given URL
59 | /// and returns by reference the encoding used to interpret the
60 | /// data. Errors are written into the inout `error` argument.
61 | init?(contentsOfURL url: NSURL, usedEncoding enc: UnsafeMutablePointer = default, error: NSErrorPointer = default)
62 |
63 | /// *[Foundation]* Produces a string containing the bytes in a given C array,
64 | /// interpreted according to a given encoding.
65 | init?(CString: UnsafePointer, encoding enc: NSStringEncoding)
66 |
67 | /// *[Foundation]* Produces a string created by copying the data from a given
68 | /// C array of UTF8-encoded bytes.
69 | init?(UTF8String bytes: UnsafePointer)
70 |
71 | /// *[Foundation]* Returns a Boolean value that indicates whether the
72 | /// `String` can be converted to a given encoding without loss of
73 | /// information.
74 | func canBeConvertedToEncoding(encoding: NSStringEncoding) -> Bool
75 |
76 | /// *[Foundation]* Produce a string with the first character from each word changed
77 | /// to the corresponding uppercase value.
78 | var capitalizedString: String { get }
79 |
80 | /// *[Foundation]* Returns a capitalized representation of the `String`
81 | /// using the specified locale.
82 | func capitalizedStringWithLocale(locale: NSLocale?) -> String
83 |
84 | /// *[Foundation]* Returns the result of invoking `compare:options:` with
85 | /// `NSCaseInsensitiveSearch` as the only option.
86 | func caseInsensitiveCompare(aString: String) -> NSComparisonResult
87 |
88 | /// *[Foundation]* Returns a string containing characters the `String` and a
89 | /// given string have in common, starting from the beginning of each
90 | /// up to the first characters that aren’t equivalent.
91 | func commonPrefixWithString(aString: String, options: NSStringCompareOptions) -> String
92 |
93 | /// *[Foundation]* Compares the string using the specified options and
94 | /// returns the lexical ordering for the range.
95 | func compare(aString: String, options mask: NSStringCompareOptions = default, range: Range? = default, locale: NSLocale? = default) -> NSComparisonResult
96 |
97 | /// *[Foundation]* Interprets the `String` as a path in the file system and
98 | /// attempts to perform filename completion, returning a numeric
99 | /// value that indicates whether a match was possible, and by
100 | /// reference the longest path that matches the `String`.
101 | /// Returns the actual number of matching paths.
102 | func completePathIntoString(_ outputName: UnsafeMutablePointer = default, caseSensitive: Bool, matchesIntoArray: UnsafeMutablePointer<[String]> = default, filterTypes: [String]? = default) -> Int
103 |
104 | /// *[Foundation]* Returns an array containing substrings from the `String`
105 | /// that have been divided by characters in a given set.
106 | func componentsSeparatedByCharactersInSet(separator: NSCharacterSet) -> [String]
107 |
108 | /// *[Foundation]* Returns an array containing substrings from the `String`
109 | /// that have been divided by a given separator.
110 | func componentsSeparatedByString(separator: String) -> [String]
111 |
112 | /// *[Foundation]* Returns a representation of the `String` as a C string
113 | /// using a given encoding.
114 | func cStringUsingEncoding(encoding: NSStringEncoding) -> [CChar]?
115 |
116 | /// *[Foundation]* Returns an `NSData` object containing a representation of
117 | /// the `String` encoded using a given encoding.
118 | func dataUsingEncoding(encoding: NSStringEncoding, allowLossyConversion: Bool = default) -> NSData?
119 |
120 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
121 | /// contents using Form D.
122 | var decomposedStringWithCanonicalMapping: String { get }
123 |
124 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
125 | /// contents using Form KD.
126 | var decomposedStringWithCompatibilityMapping: String { get }
127 |
128 | /// *[Foundation]* Enumerates all the lines in a string.
129 | func enumerateLines(body: (line: String, inout stop: Bool) -> ())
130 |
131 | /// *[Foundation]* Performs linguistic analysis on the specified string by
132 | /// enumerating the specific range of the string, providing the
133 | /// Block with the located tags.
134 | func enumerateLinguisticTagsInRange(range: Range, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions, orthography: NSOrthography?, _ body: (String, Range, Range, inout Bool) -> ())
135 |
136 | /// *[Foundation]* Enumerates the substrings of the specified type in the
137 | /// specified range of the string.
138 | func enumerateSubstringsInRange(range: Range, options opts: NSStringEnumerationOptions, _ body: (substring: String, substringRange: Range, enclosingRange: Range, inout Bool) -> ())
139 |
140 | /// *[Foundation]* Returns the fastest encoding to which the `String` may be
141 | /// converted without loss of information.
142 | var fastestEncoding: NSStringEncoding { get }
143 |
144 | /// *[Foundation]* Returns a file system-specific representation of the `String`.
145 | func fileSystemRepresentation() -> [CChar]
146 |
147 | /// *[Foundation]* Gets a given range of characters as bytes in a specified encoding.
148 | /// Note: will get a maximum of `min(buffer.count, maxLength)` bytes.
149 | func getBytes(inout buffer: [UInt8], maxLength: Int, usedLength: UnsafeMutablePointer, encoding: NSStringEncoding, options: NSStringEncodingConversionOptions, range: Range, remainingRange: UnsafeMutablePointer>) -> Bool
150 |
151 | /// *[Foundation]* Converts the `String`’s content to a given encoding and
152 | /// stores them in a buffer. Note: will store a maximum of
153 | /// `min(buffer.count, maxLength)` bytes.
154 | func getCString(inout buffer: [CChar], maxLength: Int, encoding: NSStringEncoding) -> Bool
155 |
156 | /// *[Foundation]* Interprets the `String` as a system-independent path and
157 | /// fills a buffer with a C-string in a format and encoding suitable
158 | /// for use with file-system calls. Note: will store a maximum of
159 | /// `min(buffer.count, maxLength)` bytes.
160 | func getFileSystemRepresentation(inout buffer: [CChar], maxLength: Int) -> Bool
161 |
162 | /// *[Foundation]* Returns by reference the beginning of the first line and
163 | /// the end of the last line touched by the given range.
164 | func getLineStart(start: UnsafeMutablePointer, end: UnsafeMutablePointer, contentsEnd: UnsafeMutablePointer, forRange: Range)
165 |
166 | /// *[Foundation]* Returns by reference the beginning of the first paragraph
167 | /// and the end of the last paragraph touched by the given range.
168 | func getParagraphStart(start: UnsafeMutablePointer, end: UnsafeMutablePointer, contentsEnd: UnsafeMutablePointer, forRange: Range)
169 |
170 | /// *[Foundation]* An unsigned integer that can be used as a hash table address.
171 | var hash: Int { get }
172 |
173 | /// *[Foundation]* Produces an initialized `NSString` object equivalent to the given
174 | /// `bytes` interpreted in the given `encoding`.
175 | init?(bytes: S, encoding: NSStringEncoding)
176 |
177 | /// *[Foundation]* Produces an initialized `String` object that contains a
178 | /// given number of bytes from a given buffer of bytes interpreted
179 | /// in a given encoding, and optionally frees the buffer. WARNING:
180 | /// this initializer is not memory-safe!
181 | init?(bytesNoCopy bytes: UnsafeMutablePointer, length: Int, encoding: NSStringEncoding, freeWhenDone flag: Bool)
182 |
183 | /// *[Foundation]* Returns an initialized `String` object that contains a
184 | /// given number of characters from a given array of Unicode
185 | /// characters.
186 | init(utf16CodeUnits: UnsafePointer, count: Int)
187 |
188 | /// *[Foundation]* Returns an initialized `String` object that contains a given
189 | /// number of characters from a given array of UTF-16 Code Units
190 | init(utf16CodeUnitsNoCopy: UnsafePointer, count: Int, freeWhenDone flag: Bool)
191 |
192 | /// *[Foundation]* Returns a `String` object initialized by using a given
193 | /// format string as a template into which the remaining argument
194 | /// values are substituted.
195 | init(format: String, _ arguments: CVarArgType...)
196 |
197 | /// *[Foundation]* Returns a `String` object initialized by using a given
198 | /// format string as a template into which the remaining argument
199 | /// values are substituted according to the user’s default locale.
200 | init(format: String, arguments: [CVarArgType])
201 |
202 | /// *[Foundation]* Returns a `String` object initialized by using a given
203 | /// format string as a template into which the remaining argument
204 | /// values are substituted according to given locale information.
205 | init(format: String, locale: NSLocale?, _ args: CVarArgType...)
206 |
207 | /// *[Foundation]* Returns a `String` object initialized by using a given
208 | /// format string as a template into which the remaining argument
209 | /// values are substituted according to given locale information.
210 | init(format: String, locale: NSLocale?, arguments: [CVarArgType])
211 |
212 | /// *[Foundation]* Returns the last path component of the `String`.
213 | var lastPathComponent: String { get }
214 |
215 | /// *[Foundation]* Returns the number of Unicode characters in the `String`.
216 | var utf16Count: Int { get }
217 |
218 | /// *[Foundation]* Returns the number of bytes required to store the
219 | /// `String` in a given encoding.
220 | func lengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
221 |
222 | /// *[Foundation]* Returns the range of characters representing the line or lines
223 | /// containing a given range.
224 | func lineRangeForRange(aRange: Range) -> Range
225 |
226 | /// *[Foundation]* Returns an array of linguistic tags for the specified
227 | /// range and requested tags within the receiving string.
228 | func linguisticTagsInRange(range: Range, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions = default, orthography: NSOrthography? = default, tokenRanges: UnsafeMutablePointer<[Range]> = default) -> [String]
229 |
230 | /// *[Foundation]* Compares the string and a given string using a
231 | /// case-insensitive, localized, comparison.
232 | func localizedCaseInsensitiveCompare(aString: String) -> NSComparisonResult
233 |
234 | /// *[Foundation]* Compares the string and a given string using a localized
235 | /// comparison.
236 | func localizedCompare(aString: String) -> NSComparisonResult
237 |
238 | /// *[Foundation]* Compares strings as sorted by the Finder.
239 | func localizedStandardCompare(string: String) -> NSComparisonResult
240 |
241 | /// *[Foundation]* Returns a version of the string with all letters
242 | /// converted to lowercase, taking into account the specified
243 | /// locale.
244 | func lowercaseStringWithLocale(locale: NSLocale) -> String
245 |
246 | /// *[Foundation]* Returns the maximum number of bytes needed to store the
247 | /// `String` in a given encoding.
248 | func maximumLengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
249 |
250 | /// *[Foundation]* Returns the range of characters representing the
251 | /// paragraph or paragraphs containing a given range.
252 | func paragraphRangeForRange(aRange: Range) -> Range
253 |
254 | /// *[Foundation]* Returns an array of NSString objects containing, in
255 | /// order, each path component of the `String`.
256 | var pathComponents: [String] { get }
257 |
258 | /// *[Foundation]* Interprets the `String` as a path and returns the
259 | /// `String`’s extension, if any.
260 | var pathExtension: String { get }
261 |
262 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
263 | /// contents using Form C.
264 | var precomposedStringWithCanonicalMapping: String { get }
265 |
266 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
267 | /// contents using Form KC.
268 | var precomposedStringWithCompatibilityMapping: String { get }
269 |
270 | /// *[Foundation]* Parses the `String` as a text representation of a
271 | /// property list, returning an NSString, NSData, NSArray, or
272 | /// NSDictionary object, according to the topmost element.
273 | func propertyList() -> AnyObject
274 |
275 | /// *[Foundation]* Returns a dictionary object initialized with the keys and
276 | /// values found in the `String`.
277 | func propertyListFromStringsFileFormat() -> [String : String]
278 |
279 | /// *[Foundation]* Finds and returns the range in the `String` of the first
280 | /// character from a given character set found in a given range with
281 | /// given options.
282 | func rangeOfCharacterFromSet(aSet: NSCharacterSet, options mask: NSStringCompareOptions = default, range aRange: Range? = default) -> Range?
283 |
284 | /// *[Foundation]* Returns the range in the `String` of the composed
285 | /// character sequence located at a given index.
286 | func rangeOfComposedCharacterSequenceAtIndex(anIndex: String.Index) -> Range
287 |
288 | /// *[Foundation]* Returns the range in the string of the composed character
289 | /// sequences for a given range.
290 | func rangeOfComposedCharacterSequencesForRange(range: Range) -> Range
291 |
292 | /// *[Foundation]* Finds and returns the range of the first occurrence of a
293 | /// given string within a given range of the `String`, subject to
294 | /// given options, using the specified locale, if any.
295 | func rangeOfString(aString: String, options mask: NSStringCompareOptions = default, range searchRange: Range? = default, locale: NSLocale? = default) -> Range?
296 |
297 | /// *[Foundation]* Returns the smallest encoding to which the `String` can
298 | /// be converted without loss of information.
299 | var smallestEncoding: NSStringEncoding { get }
300 |
301 | /// *[Foundation]* Returns a new string that replaces the current home
302 | /// directory portion of the current path with a tilde (`~`)
303 | /// character.
304 | var stringByAbbreviatingWithTildeInPath: String { get }
305 |
306 | /// *[Foundation]* Returns a new string made from the `String` by replacing
307 | /// all characters not in the specified set with percent encoded
308 | /// characters.
309 | func stringByAddingPercentEncodingWithAllowedCharacters(allowedCharacters: NSCharacterSet) -> String?
310 |
311 | /// *[Foundation]* Returns a representation of the `String` using a given
312 | /// encoding to determine the percent escapes necessary to convert
313 | /// the `String` into a legal URL string.
314 | func stringByAddingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
315 |
316 | /// *[Foundation]* Returns a string made by appending to the `String` a
317 | /// string constructed from a given format string and the following
318 | /// arguments.
319 | func stringByAppendingFormat(format: String, _ arguments: CVarArgType...) -> String
320 |
321 | /// *[Foundation]* Returns a new string made by appending to the `String` a given string.
322 | func stringByAppendingPathComponent(aString: String) -> String
323 |
324 | /// *[Foundation]* Returns a new string made by appending to the `String` an
325 | /// extension separator followed by a given extension.
326 | func stringByAppendingPathExtension(ext: String) -> String?
327 |
328 | /// *[Foundation]* Returns a new string made by appending a given string to
329 | /// the `String`.
330 | func stringByAppendingString(aString: String) -> String
331 |
332 | /// *[Foundation]* Returns a new string made by deleting the last path
333 | /// component from the `String`, along with any final path
334 | /// separator.
335 | var stringByDeletingLastPathComponent: String { get }
336 |
337 | /// *[Foundation]* Returns a new string made by deleting the extension (if
338 | /// any, and only the last) from the `String`.
339 | var stringByDeletingPathExtension: String { get }
340 |
341 | /// *[Foundation]* Returns a new string made by expanding the initial
342 | /// component of the `String` to its full path value.
343 | var stringByExpandingTildeInPath: String { get }
344 |
345 | /// *[Foundation]* Returns a string with the given character folding options
346 | /// applied.
347 | func stringByFoldingWithOptions(options: NSStringCompareOptions, locale: NSLocale) -> String
348 |
349 | /// *[Foundation]* Returns a new string formed from the `String` by either
350 | /// removing characters from the end, or by appending as many
351 | /// occurrences as necessary of a given pad string.
352 | func stringByPaddingToLength(newLength: Int, withString padString: String, startingAtIndex padIndex: Int) -> String
353 |
354 | /// *[Foundation]* Returns a new string made from the `String` by replacing
355 | /// all percent encoded sequences with the matching UTF-8
356 | /// characters.
357 | var stringByRemovingPercentEncoding: String? { get }
358 |
359 | /// *[Foundation]* Returns a new string in which the characters in a
360 | /// specified range of the `String` are replaced by a given string.
361 | func stringByReplacingCharactersInRange(range: Range, withString replacement: String) -> String
362 |
363 | /// *[Foundation]* Returns a new string in which all occurrences of a target
364 | /// string in a specified range of the `String` are replaced by
365 | /// another given string.
366 | func stringByReplacingOccurrencesOfString(target: String, withString replacement: String, options: NSStringCompareOptions = default, range searchRange: Range? = default) -> String
367 |
368 | /// *[Foundation]* Returns a new string made by replacing in the `String`
369 | /// all percent escapes with the matching characters as determined
370 | /// by a given encoding.
371 | func stringByReplacingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
372 |
373 | /// *[Foundation]* Returns a new string made from the `String` by resolving
374 | /// all symbolic links and standardizing path.
375 | var stringByResolvingSymlinksInPath: String { get }
376 |
377 | /// *[Foundation]* Returns a new string made by removing extraneous path
378 | /// components from the `String`.
379 | var stringByStandardizingPath: String { get }
380 |
381 | /// *[Foundation]* Returns a new string made by removing from both ends of
382 | /// the `String` characters contained in a given character set.
383 | func stringByTrimmingCharactersInSet(set: NSCharacterSet) -> String
384 |
385 | /// *[Foundation]* Returns an array of strings made by separately appending
386 | /// to the `String` each string in in a given array.
387 | func stringsByAppendingPaths(paths: [String]) -> [String]
388 |
389 | /// *[Foundation]* Returns a new string containing the characters of the
390 | /// `String` from the one at a given index to the end.
391 | func substringFromIndex(index: String.Index) -> String
392 |
393 | /// *[Foundation]* Returns a new string containing the characters of the
394 | /// `String` up to, but not including, the one at a given index.
395 | func substringToIndex(index: String.Index) -> String
396 |
397 | /// *[Foundation]* Returns a string object containing the characters of the
398 | /// `String` that lie within a given range.
399 | func substringWithRange(aRange: Range) -> String
400 |
401 | /// *[Foundation]* Returns a version of the string with all letters
402 | /// converted to uppercase, taking into account the specified
403 | /// locale.
404 | func uppercaseStringWithLocale(locale: NSLocale) -> String
405 |
406 | /// *[Foundation]* Writes the contents of the `String` to a file at a given
407 | /// path using a given encoding.
408 | func writeToFile(path: String, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding, error: NSErrorPointer = default) -> Bool
409 |
410 | /// *[Foundation]* Writes the contents of the `String` to the URL specified
411 | /// by url using the specified encoding.
412 | func writeToURL(url: NSURL, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding, error: NSErrorPointer = default) -> Bool
413 | }
414 |
--------------------------------------------------------------------------------
/data/addenda/2.0/foundation.txt:
--------------------------------------------------------------------------------
1 | extension String {
2 | /// *[Foundation]* Returns an Array of the encodings string objects support
3 | /// in the application’s environment.
4 | @warn_unused_result
5 | public static func availableStringEncodings() -> [NSStringEncoding]
6 | /// *[Foundation]* Returns the C-string encoding assumed for any method accepting
7 | /// a C string as an argument.
8 | @warn_unused_result
9 | public static func defaultCStringEncoding() -> NSStringEncoding
10 | /// Returns a human-readable string giving the name of a given encoding.
11 | @warn_unused_result
12 | public static func localizedNameOfStringEncoding(encoding: NSStringEncoding) -> String
13 | /// *[Foundation]* Returns a string created by using a given format string as a
14 | /// template into which the remaining argument values are substituted
15 | /// according to the user's default locale.
16 | @warn_unused_result
17 | public static func localizedStringWithFormat(format: String, _ arguments: CVarArgType...) -> String
18 | /// *[Foundation]* Produces a string created by copying the data from a given
19 | /// C array of UTF8-encoded bytes.
20 | public init?(UTF8String bytes: UnsafePointer)
21 | /// *[Foundation]* Returns a Boolean value that indicates whether the
22 | /// `String` can be converted to a given encoding without loss of
23 | /// information.
24 | @warn_unused_result
25 | public func canBeConvertedToEncoding(encoding: NSStringEncoding) -> Bool
26 | /// *[Foundation]* Produce a string with the first character from each word changed
27 | /// to the corresponding uppercase value.
28 | public var capitalizedString: String { get }
29 | /// *[Foundation]* A capitalized representation of the `String` that is produced
30 | /// using the current locale.
31 | public var localizedCapitalizedString: String { get }
32 | /// *[Foundation]* Returns a capitalized representation of the `String`
33 | /// using the specified locale.
34 | @warn_unused_result
35 | public func capitalizedStringWithLocale(locale: NSLocale?) -> String
36 | /// *[Foundation]* Returns the result of invoking `compare:options:` with
37 | /// `NSCaseInsensitiveSearch` as the only option.
38 | @warn_unused_result
39 | public func caseInsensitiveCompare(aString: String) -> NSComparisonResult
40 | /// *[Foundation]* Returns a string containing characters the `String` and a
41 | /// given string have in common, starting from the beginning of each
42 | /// up to the first characters that aren’t equivalent.
43 | @warn_unused_result
44 | public func commonPrefixWithString(aString: String, options: NSStringCompareOptions) -> String
45 | /// *[Foundation]* Compares the string using the specified options and
46 | /// returns the lexical ordering for the range.
47 | @warn_unused_result
48 | public func compare(aString: String, options mask: NSStringCompareOptions = default, range: Range? = default, locale: NSLocale? = default) -> NSComparisonResult
49 | /// *[Foundation]* Interprets the `String` as a path in the file system and
50 | /// attempts to perform filename completion, returning a numeric
51 | /// value that indicates whether a match was possible, and by
52 | /// reference the longest path that matches the `String`.
53 | /// Returns the actual number of matching paths.
54 | @warn_unused_result
55 | public func completePathIntoString(outputName: UnsafeMutablePointer = default, caseSensitive: Bool, matchesIntoArray: UnsafeMutablePointer<[String]> = default, filterTypes: [String]? = default) -> Int
56 | /// *[Foundation]* Returns an array containing substrings from the `String`
57 | /// that have been divided by characters in a given set.
58 | @warn_unused_result
59 | public func componentsSeparatedByCharactersInSet(separator: NSCharacterSet) -> [String]
60 | /// *[Foundation]* Returns an array containing substrings from the `String`
61 | /// that have been divided by a given separator.
62 | public func componentsSeparatedByString(separator: String) -> [String]
63 | /// *[Foundation]* Returns a representation of the `String` as a C string
64 | /// using a given encoding.
65 | @warn_unused_result
66 | public func cStringUsingEncoding(encoding: NSStringEncoding) -> [CChar]?
67 | /// *[Foundation]* Returns an `NSData` object containing a representation of
68 | /// the `String` encoded using a given encoding.
69 | @warn_unused_result
70 | public func dataUsingEncoding(encoding: NSStringEncoding, allowLossyConversion: Bool = default) -> NSData?
71 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
72 | /// contents using Form D.
73 | public var decomposedStringWithCanonicalMapping: String { get }
74 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
75 | /// contents using Form KD.
76 | public var decomposedStringWithCompatibilityMapping: String { get }
77 | /// *[Foundation]* Enumerates all the lines in a string.
78 | public func enumerateLines(body: (line: String, inout stop: Bool) -> ())
79 | /// *[Foundation]* Performs linguistic analysis on the specified string by
80 | /// enumerating the specific range of the string, providing the
81 | /// Block with the located tags.
82 | public func enumerateLinguisticTagsInRange(range: Range, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions, orthography: NSOrthography?, _ body: (String, Range, Range, inout Bool) -> ())
83 | /// *[Foundation]* Enumerates the substrings of the specified type in the
84 | /// specified range of the string.
85 | public func enumerateSubstringsInRange(range: Range, options opts: NSStringEnumerationOptions, _ body: (substring: String?, substringRange: Range, enclosingRange: Range, inout Bool) -> ())
86 | /// *[Foundation]* Returns the fastest encoding to which the `String` may be
87 | /// converted without loss of information.
88 | public var fastestEncoding: NSStringEncoding { get }
89 | /// *[Foundation]* Writes the given `range` of characters into `buffer` in a given
90 | /// `encoding`, without any allocations. Does not NULL-terminate.
91 | ///
92 | /// - Parameter buffer: A buffer into which to store the bytes from
93 | /// the receiver. The returned bytes are not NUL-terminated.
94 | ///
95 | /// - Parameter maxBufferCount: The maximum number of bytes to write
96 | /// to buffer.
97 | ///
98 | /// - Parameter usedBufferCount: The number of bytes used from
99 | /// buffer. Pass `nil` if you do not need this value.
100 | ///
101 | /// - Parameter encoding: The encoding to use for the returned bytes.
102 | ///
103 | /// - Parameter options: A mask to specify options to use for
104 | /// converting the receiver’s contents to `encoding` (if conversion
105 | /// is necessary).
106 | ///
107 | /// - Parameter range: The range of characters in the receiver to get.
108 | ///
109 | /// - Parameter leftover: The remaining range. Pass `nil` If you do
110 | /// not need this value.
111 | ///
112 | /// - Returns: `true` iff some characters were converted.
113 | ///
114 | /// - Note: Conversion stops when the buffer fills or when the
115 | /// conversion isn't possible due to the chosen encoding.
116 | ///
117 | /// - Note: will get a maximum of `min(buffer.count, maxLength)` bytes.
118 | public func getBytes(inout buffer: [UInt8], maxLength maxBufferCount: Int, usedLength usedBufferCount: UnsafeMutablePointer, encoding: NSStringEncoding, options: NSStringEncodingConversionOptions, range: Range, remainingRange leftover: UnsafeMutablePointer>) -> Bool
119 | /// *[Foundation]* Converts the `String`’s content to a given encoding and
120 | /// stores them in a buffer.
121 | /// - Note: will store a maximum of `min(buffer.count, maxLength)` bytes.
122 | public func getCString(inout buffer: [CChar], maxLength: Int, encoding: NSStringEncoding) -> Bool
123 | /// *[Foundation]* Returns by reference the beginning of the first line and
124 | /// the end of the last line touched by the given range.
125 | public func getLineStart(start: UnsafeMutablePointer, end: UnsafeMutablePointer, contentsEnd: UnsafeMutablePointer, forRange: Range)
126 | /// *[Foundation]* Returns by reference the beginning of the first paragraph
127 | /// and the end of the last paragraph touched by the given range.
128 | public func getParagraphStart(start: UnsafeMutablePointer, end: UnsafeMutablePointer, contentsEnd: UnsafeMutablePointer, forRange: Range)
129 | /// *[Foundation]* An unsigned integer that can be used as a hash table address.
130 | public var hash: Int { get }
131 | /// *[Foundation]* Produces an initialized `NSString` object equivalent to the given
132 | /// `bytes` interpreted in the given `encoding`.
133 | public init?(bytes: S, encoding: NSStringEncoding)
134 | /// *[Foundation]* Produces an initialized `String` object that contains a
135 | /// given number of bytes from a given buffer of bytes interpreted
136 | /// in a given encoding, and optionally frees the buffer. WARNING:
137 | /// this initializer is not memory-safe!
138 | public init?(bytesNoCopy bytes: UnsafeMutablePointer, length: Int, encoding: NSStringEncoding, freeWhenDone flag: Bool)
139 | /// *[Foundation]* Returns an initialized `String` object that contains a
140 | /// given number of characters from a given array of Unicode
141 | /// characters.
142 | public init(utf16CodeUnits: UnsafePointer, count: Int)
143 | /// *[Foundation]* Returns an initialized `String` object that contains a given
144 | /// number of characters from a given array of UTF-16 Code Units
145 | public init(utf16CodeUnitsNoCopy: UnsafePointer, count: Int, freeWhenDone flag: Bool)
146 | /// *[Foundation]* Produces a string created by reading data from the file at a
147 | /// given path interpreted using a given encoding.
148 | public init(contentsOfFile path: String, encoding enc: NSStringEncoding) throws
149 | /// *[Foundation]* Produces a string created by reading data from the file at
150 | /// a given path and returns by reference the encoding used to
151 | /// interpret the file.
152 | public init(contentsOfFile path: String, usedEncoding: UnsafeMutablePointer = default) throws
153 | /// *[Foundation]* Produces a string created by reading data from a given URL
154 | /// interpreted using a given encoding. Errors are written into the
155 | /// inout `error` argument.
156 | public init(contentsOfURL url: NSURL, encoding enc: NSStringEncoding) throws
157 | /// *[Foundation]* Produces a string created by reading data from a given URL
158 | /// and returns by reference the encoding used to interpret the
159 | /// data. Errors are written into the inout `error` argument.
160 | public init(contentsOfURL url: NSURL, usedEncoding enc: UnsafeMutablePointer = default) throws
161 | /// *[Foundation]* Produces a string containing the bytes in a given C array,
162 | /// interpreted according to a given encoding.
163 | public init?(CString: UnsafePointer, encoding enc: NSStringEncoding)
164 | /// *[Foundation]* Returns a `String` initialized by converting given `data` into
165 | /// Unicode characters using a given `encoding`.
166 | public init?(data: NSData, encoding: NSStringEncoding)
167 | /// *[Foundation]* Returns a `String` object initialized by using a given
168 | /// format string as a template into which the remaining argument
169 | /// values are substituted.
170 | public init(format: String, _ arguments: CVarArgType...)
171 | /// *[Foundation]* Returns a `String` object initialized by using a given
172 | /// format string as a template into which the remaining argument
173 | /// values are substituted according to the user’s default locale.
174 | public init(format: String, arguments: [CVarArgType])
175 | /// *[Foundation]* Returns a `String` object initialized by using a given
176 | /// format string as a template into which the remaining argument
177 | /// values are substituted according to given locale information.
178 | public init(format: String, locale: NSLocale?, _ args: CVarArgType...)
179 | /// *[Foundation]* Returns a `String` object initialized by using a given
180 | /// format string as a template into which the remaining argument
181 | /// values are substituted according to given locale information.
182 | public init(format: String, locale: NSLocale?, arguments: [CVarArgType])
183 | /// *[Foundation]* Returns the number of bytes required to store the
184 | /// `String` in a given encoding.
185 | @warn_unused_result
186 | public func lengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
187 | /// *[Foundation]* Returns the range of characters representing the line or lines
188 | /// containing a given range.
189 | @warn_unused_result
190 | public func lineRangeForRange(aRange: Range) -> Range
191 | /// *[Foundation]* Returns an array of linguistic tags for the specified
192 | /// range and requested tags within the receiving string.
193 | @warn_unused_result
194 | public func linguisticTagsInRange(range: Range, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions = default, orthography: NSOrthography? = default, tokenRanges: UnsafeMutablePointer<[Range]> = default) -> [String]
195 | /// *[Foundation]* Compares the string and a given string using a
196 | /// case-insensitive, localized, comparison.
197 | @warn_unused_result
198 | public func localizedCaseInsensitiveCompare(aString: String) -> NSComparisonResult
199 | /// *[Foundation]* Compares the string and a given string using a localized
200 | /// comparison.
201 | @warn_unused_result
202 | public func localizedCompare(aString: String) -> NSComparisonResult
203 | /// *[Foundation]* Compares strings as sorted by the Finder.
204 | @warn_unused_result
205 | public func localizedStandardCompare(string: String) -> NSComparisonResult
206 | /// *[Foundation]* A lowercase version of the string that is produced using the current
207 | /// locale.
208 | public var localizedLowercaseString: String { get }
209 | /// *[Foundation]* Returns a version of the string with all letters
210 | /// converted to lowercase, taking into account the specified
211 | /// locale.
212 | @warn_unused_result
213 | public func lowercaseStringWithLocale(locale: NSLocale?) -> String
214 | /// *[Foundation]* Returns the maximum number of bytes needed to store the
215 | /// `String` in a given encoding.
216 | @warn_unused_result
217 | public func maximumLengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
218 | /// *[Foundation]* Returns the range of characters representing the
219 | /// paragraph or paragraphs containing a given range.
220 | @warn_unused_result
221 | public func paragraphRangeForRange(aRange: Range) -> Range
222 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
223 | /// contents using Form C.
224 | public var precomposedStringWithCanonicalMapping: String { get }
225 | /// *[Foundation]* Returns a string made by normalizing the `String`’s
226 | /// contents using Form KC.
227 | public var precomposedStringWithCompatibilityMapping: String { get }
228 | /// *[Foundation]* Parses the `String` as a text representation of a
229 | /// property list, returning an NSString, NSData, NSArray, or
230 | /// NSDictionary object, according to the topmost element.
231 | @warn_unused_result
232 | public func propertyList() -> AnyObject
233 | /// *[Foundation]* Returns a dictionary object initialized with the keys and
234 | /// values found in the `String`.
235 | @warn_unused_result
236 | public func propertyListFromStringsFileFormat() -> [String : String]
237 | /// *[Foundation]* Finds and returns the range in the `String` of the first
238 | /// character from a given character set found in a given range with
239 | /// given options.
240 | @warn_unused_result
241 | public func rangeOfCharacterFromSet(aSet: NSCharacterSet, options mask: NSStringCompareOptions = default, range aRange: Range? = default) -> Range?
242 | /// *[Foundation]* Returns the range in the `String` of the composed
243 | /// character sequence located at a given index.
244 | @warn_unused_result
245 | public func rangeOfComposedCharacterSequenceAtIndex(anIndex: Index) -> Range
246 | /// *[Foundation]* Returns the range in the string of the composed character
247 | /// sequences for a given range.
248 | @warn_unused_result
249 | public func rangeOfComposedCharacterSequencesForRange(range: Range) -> Range
250 | /// *[Foundation]* Finds and returns the range of the first occurrence of a
251 | /// given string within a given range of the `String`, subject to
252 | /// given options, using the specified locale, if any.
253 | @warn_unused_result
254 | public func rangeOfString(aString: String, options mask: NSStringCompareOptions = default, range searchRange: Range? = default, locale: NSLocale? = default) -> Range?
255 | /// *[Foundation]* Returns `true` if `self` contains `string`, taking the current locale
256 | /// into account.
257 | ///
258 | /// This is the most appropriate method for doing user-level string searches,
259 | /// similar to how searches are done generally in the system. The search is
260 | /// locale-aware, case and diacritic insensitive. The exact list of search
261 | /// options applied may change over time.
262 | @warn_unused_result
263 | public func localizedStandardContainsString(string: String) -> Bool
264 | /// *[Foundation]* Finds and returns the range of the first occurrence of a given string,
265 | /// taking the current locale into account. Returns `nil` if the string was
266 | /// not found.
267 | ///
268 | /// This is the most appropriate method for doing user-level string searches,
269 | /// similar to how searches are done generally in the system. The search is
270 | /// locale-aware, case and diacritic insensitive. The exact list of search
271 | /// options applied may change over time.
272 | @warn_unused_result
273 | public func localizedStandardRangeOfString(string: String) -> Range?
274 | /// *[Foundation]* Returns the smallest encoding to which the `String` can
275 | /// be converted without loss of information.
276 | public var smallestEncoding: NSStringEncoding { get }
277 | /// *[Foundation]* Returns a new string made from the `String` by replacing
278 | /// all characters not in the specified set with percent encoded
279 | /// characters.
280 | @warn_unused_result
281 | public func stringByAddingPercentEncodingWithAllowedCharacters(allowedCharacters: NSCharacterSet) -> String?
282 | /// *[Foundation]* Returns a representation of the `String` using a given
283 | /// encoding to determine the percent escapes necessary to convert
284 | /// the `String` into a legal URL string.
285 | @available(*, deprecated, message="Use stringByAddingPercentEncodingWithAllowedCharacters(_:) instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.")
286 | public func stringByAddingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
287 | /// *[Foundation]* Returns a string made by appending to the `String` a
288 | /// string constructed from a given format string and the following
289 | /// arguments.
290 | @warn_unused_result
291 | public func stringByAppendingFormat(format: String, _ arguments: CVarArgType...) -> String
292 | /// *[Foundation]* Returns a new string made by appending a given string to
293 | /// the `String`.
294 | @warn_unused_result
295 | public func stringByAppendingString(aString: String) -> String
296 | /// *[Foundation]* Returns a string with the given character folding options
297 | /// applied.
298 | @warn_unused_result
299 | public func stringByFoldingWithOptions(options: NSStringCompareOptions, locale: NSLocale?) -> String
300 | /// *[Foundation]* Returns a new string formed from the `String` by either
301 | /// removing characters from the end, or by appending as many
302 | /// occurrences as necessary of a given pad string.
303 | @warn_unused_result
304 | public func stringByPaddingToLength(newLength: Int, withString padString: String, startingAtIndex padIndex: Int) -> String
305 | /// *[Foundation]* Returns a new string made from the `String` by replacing
306 | /// all percent encoded sequences with the matching UTF-8
307 | /// characters.
308 | public var stringByRemovingPercentEncoding: String? { get }
309 | /// *[Foundation]* Returns a new string in which the characters in a
310 | /// specified range of the `String` are replaced by a given string.
311 | @warn_unused_result
312 | public func stringByReplacingCharactersInRange(range: Range, withString replacement: String) -> String
313 | /// *[Foundation]* Returns a new string in which all occurrences of a target
314 | /// string in a specified range of the `String` are replaced by
315 | /// another given string.
316 | @warn_unused_result
317 | public func stringByReplacingOccurrencesOfString(target: String, withString replacement: String, options: NSStringCompareOptions = default, range searchRange: Range? = default) -> String
318 | /// *[Foundation]* Returns a new string made by replacing in the `String`
319 | /// all percent escapes with the matching characters as determined
320 | /// by a given encoding.
321 | @available(*, deprecated, message="Use stringByRemovingPercentEncoding instead, which always uses the recommended UTF-8 encoding.")
322 | public func stringByReplacingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
323 | /// *[Foundation]* Returns a new string made by removing from both ends of
324 | /// the `String` characters contained in a given character set.
325 | @warn_unused_result
326 | public func stringByTrimmingCharactersInSet(set: NSCharacterSet) -> String
327 | /// *[Foundation]* Returns a new string containing the characters of the
328 | /// `String` from the one at a given index to the end.
329 | @warn_unused_result
330 | public func substringFromIndex(index: Index) -> String
331 | /// *[Foundation]* Returns a new string containing the characters of the
332 | /// `String` up to, but not including, the one at a given index.
333 | @warn_unused_result
334 | public func substringToIndex(index: Index) -> String
335 | /// *[Foundation]* Returns a string object containing the characters of the
336 | /// `String` that lie within a given range.
337 | @warn_unused_result
338 | public func substringWithRange(aRange: Range) -> String
339 | /// *[Foundation]* An uppercase version of the string that is produced using the current
340 | /// locale.
341 | public var localizedUppercaseString: String { get }
342 | /// *[Foundation]* Returns a version of the string with all letters
343 | /// converted to uppercase, taking into account the specified
344 | /// locale.
345 | @warn_unused_result
346 | public func uppercaseStringWithLocale(locale: NSLocale?) -> String
347 | /// *[Foundation]* Writes the contents of the `String` to a file at a given
348 | /// path using a given encoding.
349 | public func writeToFile(path: String, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding) throws
350 | /// *[Foundation]* Writes the contents of the `String` to the URL specified
351 | /// by url using the specified encoding.
352 | public func writeToURL(url: NSURL, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding) throws
353 | /// *[Foundation]* Perform string transliteration.
354 | @warn_unused_result
355 | public func stringByApplyingTransform(transform: String, reverse: Bool) -> String?
356 | /// *[Foundation]* Returns `true` iff `other` is non-empty and contained within
357 | /// `self` by case-sensitive, non-literal search.
358 | ///
359 | /// Equivalent to `self.rangeOfString(other) != nil`
360 | @warn_unused_result
361 | public func containsString(other: String) -> Bool
362 | /// *[Foundation]* Returns `true` iff `other` is non-empty and contained within
363 | /// `self` by case-insensitive, non-literal search, taking into
364 | /// account the current locale.
365 | ///
366 | /// Locale-independent case-insensitive operation, and other needs,
367 | /// can be achieved by calling
368 | /// `rangeOfString(_:options:_,range:_locale:_)`.
369 | ///
370 | /// Equivalent to
371 | ///
372 | /// self.rangeOfString(
373 | /// other, options: .CaseInsensitiveSearch,
374 | /// locale: NSLocale.currentLocale()) != nil
375 | @warn_unused_result
376 | public func localizedCaseInsensitiveContainsString(other: String) -> Bool
377 | }
378 |
379 | extension String : _ObjectiveCBridgeable {
380 | }
381 |
382 | extension String {
383 | /// *[Foundation]*
384 | public init(_ cocoaString: NSString)
385 | }
386 |
387 | extension Float : _ObjectiveCBridgeable {
388 | /// *[Foundation]*
389 | public init(_ number: NSNumber)
390 | }
391 |
392 | extension Dictionary : _ObjectiveCBridgeable {
393 | }
394 |
395 | extension Set : _ObjectiveCBridgeable {
396 | }
397 |
398 | extension Double : _ObjectiveCBridgeable {
399 | /// *[Foundation]*
400 | public init(_ number: NSNumber)
401 | }
402 |
403 |
--------------------------------------------------------------------------------
/data/addenda/3.0/foundation.txt:
--------------------------------------------------------------------------------
1 | extension String {
2 | /// *[Foundation]*
3 | /// Returns an Array of the encodings string objects support
4 | /// in the application's environment.
5 | public static func availableStringEncodings() -> [String.Encoding]
6 |
7 | /// *[Foundation]*
8 | /// Returns the C-string encoding assumed for any method accepting
9 | /// a C string as an argument.
10 | public static func defaultCStringEncoding() -> String.Encoding
11 |
12 | /// *[Foundation]*
13 | /// Returns a human-readable string giving the name of a given encoding.
14 | public static func localizedName(of encoding: String.Encoding) -> String
15 |
16 | /// *[Foundation]*
17 | /// Returns a string created by using a given format string as a
18 | /// template into which the remaining argument values are substituted
19 | /// according to the user's default locale.
20 | public static func localizedStringWithFormat(_ format: String, _ arguments: CVarArg...) -> String
21 |
22 | /// *[Foundation]*
23 | /// Produces a string created by copying the data from a given
24 | /// C array of UTF8-encoded bytes.
25 | public init?(utf8String bytes: UnsafePointer)
26 |
27 | /// *[Foundation]*
28 | /// Returns a Boolean value that indicates whether the
29 | /// `String` can be converted to a given encoding without loss of
30 | /// information.
31 | public func canBeConverted(to encoding: String.Encoding) -> Bool
32 |
33 | /// *[Foundation]*
34 | /// Produce a string with the first character from each word changed
35 | /// to the corresponding uppercase value.
36 | public var capitalized: String { get }
37 |
38 | /// *[Foundation]*
39 | /// A capitalized representation of the `String` that is produced
40 | /// using the current locale.
41 | public var localizedCapitalized: String { get }
42 |
43 | /// *[Foundation]*
44 | /// Returns a capitalized representation of the `String`
45 | /// using the specified locale.
46 | public func capitalized(with locale: Locale?) -> String
47 |
48 | /// *[Foundation]*
49 | /// Returns the result of invoking `compare:options:` with
50 | /// `NSCaseInsensitiveSearch` as the only option.
51 | public func caseInsensitiveCompare(_ aString: String) -> ComparisonResult
52 |
53 | /// *[Foundation]*
54 | /// Returns a string containing characters the `String` and a
55 | /// given string have in common, starting from the beginning of each
56 | /// up to the first characters that aren't equivalent.
57 | public func commonPrefix(with aString: String, options: CompareOptions = default) -> String
58 |
59 | /// *[Foundation]*
60 | /// Compares the string using the specified options and
61 | /// returns the lexical ordering for the range.
62 | public func compare(_ aString: String, options mask: CompareOptions = default, range: Range? = default, locale: Locale? = default) -> ComparisonResult
63 |
64 | /// *[Foundation]*
65 | /// Interprets the `String` as a path in the file system and
66 | /// attempts to perform filename completion, returning a numeric
67 | /// value that indicates whether a match was possible, and by
68 | /// reference the longest path that matches the `String`.
69 | /// Returns the actual number of matching paths.
70 | public func completePath(into outputName: UnsafeMutablePointer? = default, caseSensitive: Bool, matchesInto outputArray: UnsafeMutablePointer<[String]>? = default, filterTypes: [String]? = default) -> Int
71 |
72 | /// *[Foundation]*
73 | /// Returns an array containing substrings from the `String`
74 | /// that have been divided by characters in a given set.
75 | public func components(separatedBy separator: CharacterSet) -> [String]
76 |
77 | /// *[Foundation]*
78 | /// Returns an array containing substrings from the `String`
79 | /// that have been divided by a given separator.
80 | public func components(separatedBy separator: String) -> [String]
81 |
82 | /// *[Foundation]*
83 | /// Returns a representation of the `String` as a C string
84 | /// using a given encoding.
85 | public func cString(using encoding: String.Encoding) -> [CChar]?
86 |
87 | /// *[Foundation]*
88 | /// Returns a `Data` containing a representation of
89 | /// the `String` encoded using a given encoding.
90 | public func data(using encoding: String.Encoding, allowLossyConversion: Bool = default) -> Data?
91 |
92 | /// *[Foundation]*
93 | /// Returns a string made by normalizing the `String`'s
94 | /// contents using Form D.
95 | public var decomposedStringWithCanonicalMapping: String { get }
96 |
97 | /// *[Foundation]*
98 | /// Returns a string made by normalizing the `String`'s
99 | /// contents using Form KD.
100 | public var decomposedStringWithCompatibilityMapping: String { get }
101 |
102 | /// *[Foundation]*
103 | /// Enumerates all the lines in a string.
104 | public func enumerateLines(_ body: (line: String, stop: inout Bool) -> ())
105 |
106 | /// *[Foundation]*
107 | /// Performs linguistic analysis on the specified string by
108 | /// enumerating the specific range of the string, providing the
109 | /// Block with the located tags.
110 | public func enumerateLinguisticTags(in range: Range, scheme tagScheme: String, options opts: NSLinguisticTagger.Options = default, orthography: NSOrthography? = default, _ body: (String, Range, Range, inout Bool) -> ())
111 |
112 | /// *[Foundation]*
113 | /// Enumerates the substrings of the specified type in the
114 | /// specified range of the string.
115 | public func enumerateSubstrings(in range: Range, options opts: EnumerationOptions = default, _ body: (substring: String?, substringRange: Range, enclosingRange: Range, inout Bool) -> ())
116 |
117 | /// *[Foundation]*
118 | /// Returns the fastest encoding to which the `String` may be
119 | /// converted without loss of information.
120 | public var fastestEncoding: String.Encoding { get }
121 |
122 | /// *[Foundation]*
123 | /// Writes the given `range` of characters into `buffer` in a given
124 | /// `encoding`, without any allocations. Does not NULL-terminate.
125 | ///
126 | /// - Parameter buffer: A buffer into which to store the bytes from
127 | /// the receiver. The returned bytes are not NUL-terminated.
128 | ///
129 | /// - Parameter maxBufferCount: The maximum number of bytes to write
130 | /// to buffer.
131 | ///
132 | /// - Parameter usedBufferCount: The number of bytes used from
133 | /// buffer. Pass `nil` if you do not need this value.
134 | ///
135 | /// - Parameter encoding: The encoding to use for the returned bytes.
136 | ///
137 | /// - Parameter options: A mask to specify options to use for
138 | /// converting the receiver's contents to `encoding` (if conversion
139 | /// is necessary).
140 | ///
141 | /// - Parameter range: The range of characters in the receiver to get.
142 | ///
143 | /// - Parameter leftover: The remaining range. Pass `nil` If you do
144 | /// not need this value.
145 | ///
146 | /// - Returns: `true` iff some characters were converted.
147 | ///
148 | /// - Note: Conversion stops when the buffer fills or when the
149 | /// conversion isn't possible due to the chosen encoding.
150 | ///
151 | /// - Note: will get a maximum of `min(buffer.count, maxLength)` bytes.
152 | public func getBytes(_ buffer: inout [UInt8], maxLength maxBufferCount: Int, usedLength usedBufferCount: UnsafeMutablePointer, encoding: String.Encoding, options: EncodingConversionOptions = default, range: Range, remaining leftover: UnsafeMutablePointer>) -> Bool
153 |
154 | /// *[Foundation]*
155 | /// Converts the `String`'s content to a given encoding and
156 | /// stores them in a buffer.
157 | /// - Note: will store a maximum of `min(buffer.count, maxLength)` bytes.
158 | public func getCString(_ buffer: inout [CChar], maxLength: Int, encoding: String.Encoding) -> Bool
159 |
160 | /// *[Foundation]*
161 | /// Returns by reference the beginning of the first line and
162 | /// the end of the last line touched by the given range.
163 | public func getLineStart(_ start: UnsafeMutablePointer, end: UnsafeMutablePointer, contentsEnd: UnsafeMutablePointer, for range: Range)
164 |
165 | /// *[Foundation]*
166 | /// Returns by reference the beginning of the first paragraph
167 | /// and the end of the last paragraph touched by the given range.
168 | public func getParagraphStart(_ start: UnsafeMutablePointer, end: UnsafeMutablePointer, contentsEnd: UnsafeMutablePointer, for range: Range)
169 |
170 | /// *[Foundation]*
171 | /// An unsigned integer that can be used as a hash table address.
172 | public var hash: Int { get }
173 |
174 | /// *[Foundation]*
175 | /// Produces an initialized `NSString` object equivalent to the given
176 | /// `bytes` interpreted in the given `encoding`.
177 | public init?(bytes: S, encoding: String.Encoding)
178 |
179 | /// *[Foundation]*
180 | /// Produces an initialized `String` object that contains a
181 | /// given number of bytes from a given buffer of bytes interpreted
182 | /// in a given encoding, and optionally frees the buffer. WARNING:
183 | /// this initializer is not memory-safe!
184 | public init?(bytesNoCopy bytes: UnsafeMutablePointer, length: Int, encoding: String.Encoding, freeWhenDone flag: Bool)
185 |
186 | /// *[Foundation]*
187 | /// Returns an initialized `String` object that contains a
188 | /// given number of characters from a given array of Unicode
189 | /// characters.
190 | public init(utf16CodeUnits: UnsafePointer, count: Int)
191 |
192 | /// *[Foundation]*
193 | /// Returns an initialized `String` object that contains a given
194 | /// number of characters from a given array of UTF-16 Code Units
195 | public init(utf16CodeUnitsNoCopy: UnsafePointer, count: Int, freeWhenDone flag: Bool)
196 |
197 | /// *[Foundation]*
198 | /// Produces a string created by reading data from the file at a
199 | /// given path interpreted using a given encoding.
200 | public init(contentsOfFile path: String, encoding enc: String.Encoding) throws
201 |
202 | /// *[Foundation]*
203 | /// Produces a string created by reading data from the file at
204 | /// a given path and returns by reference the encoding used to
205 | /// interpret the file.
206 | public init(contentsOfFile path: String, usedEncoding: inout String.Encoding) throws
207 |
208 | /// *[Foundation]*
209 | public init(contentsOfFile path: String) throws
210 |
211 | /// *[Foundation]*
212 | /// Produces a string created by reading data from a given URL
213 | /// interpreted using a given encoding. Errors are written into the
214 | /// inout `error` argument.
215 | public init(contentsOf url: URL, encoding enc: String.Encoding) throws
216 |
217 | /// *[Foundation]*
218 | /// Produces a string created by reading data from a given URL
219 | /// and returns by reference the encoding used to interpret the
220 | /// data. Errors are written into the inout `error` argument.
221 | public init(contentsOf url: URL, usedEncoding: inout String.Encoding) throws
222 |
223 | /// *[Foundation]*
224 | public init(contentsOf url: URL) throws
225 |
226 | /// *[Foundation]*
227 | /// Produces a string containing the bytes in a given C array,
228 | /// interpreted according to a given encoding.
229 | public init?(cString: UnsafePointer, encoding enc: String.Encoding)
230 |
231 | /// *[Foundation]*
232 | /// Returns a `String` initialized by converting given `data` into
233 | /// Unicode characters using a given `encoding`.
234 | public init?(data: Data, encoding: String.Encoding)
235 |
236 | /// *[Foundation]*
237 | /// Returns a `String` object initialized by using a given
238 | /// format string as a template into which the remaining argument
239 | /// values are substituted.
240 | public init(format: String, _ arguments: CVarArg...)
241 |
242 | /// *[Foundation]*
243 | /// Returns a `String` object initialized by using a given
244 | /// format string as a template into which the remaining argument
245 | /// values are substituted according to the user's default locale.
246 | public init(format: String, arguments: [CVarArg])
247 |
248 | /// *[Foundation]*
249 | /// Returns a `String` object initialized by using a given
250 | /// format string as a template into which the remaining argument
251 | /// values are substituted according to given locale information.
252 | public init(format: String, locale: Locale?, _ args: CVarArg...)
253 |
254 | /// *[Foundation]*
255 | /// Returns a `String` object initialized by using a given
256 | /// format string as a template into which the remaining argument
257 | /// values are substituted according to given locale information.
258 | public init(format: String, locale: Locale?, arguments: [CVarArg])
259 |
260 | /// *[Foundation]*
261 | /// Returns the number of bytes required to store the
262 | /// `String` in a given encoding.
263 | public func lengthOfBytes(using encoding: String.Encoding) -> Int
264 |
265 | /// *[Foundation]*
266 | /// Returns the range of characters representing the line or lines
267 | /// containing a given range.
268 | public func lineRange(for aRange: Range) -> Range
269 |
270 | /// *[Foundation]*
271 | /// Returns an array of linguistic tags for the specified
272 | /// range and requested tags within the receiving string.
273 | public func linguisticTags(in range: Range, scheme tagScheme: String, options opts: NSLinguisticTagger.Options = default, orthography: NSOrthography? = default, tokenRanges: UnsafeMutablePointer<[Range]>? = default) -> [String]
274 |
275 | /// *[Foundation]*
276 | /// Compares the string and a given string using a
277 | /// case-insensitive, localized, comparison.
278 | public func localizedCaseInsensitiveCompare(_ aString: String) -> ComparisonResult
279 |
280 | /// *[Foundation]*
281 | /// Compares the string and a given string using a localized
282 | /// comparison.
283 | public func localizedCompare(_ aString: String) -> ComparisonResult
284 |
285 | /// *[Foundation]*
286 | /// Compares strings as sorted by the Finder.
287 | public func localizedStandardCompare(_ string: String) -> ComparisonResult
288 |
289 | /// *[Foundation]*
290 | /// A lowercase version of the string that is produced using the current
291 | /// locale.
292 | public var localizedLowercase: String { get }
293 |
294 | /// *[Foundation]*
295 | /// Returns a version of the string with all letters
296 | /// converted to lowercase, taking into account the specified
297 | /// locale.
298 | public func lowercased(with locale: Locale?) -> String
299 |
300 | /// *[Foundation]*
301 | /// Returns the maximum number of bytes needed to store the
302 | /// `String` in a given encoding.
303 | public func maximumLengthOfBytes(using encoding: String.Encoding) -> Int
304 |
305 | /// *[Foundation]*
306 | /// Returns the range of characters representing the
307 | /// paragraph or paragraphs containing a given range.
308 | public func paragraphRange(for aRange: Range) -> Range
309 |
310 | /// *[Foundation]*
311 | /// Returns a string made by normalizing the `String`'s
312 | /// contents using Form C.
313 | public var precomposedStringWithCanonicalMapping: String { get }
314 |
315 | /// *[Foundation]*
316 | /// Returns a string made by normalizing the `String`'s
317 | /// contents using Form KC.
318 | public var precomposedStringWithCompatibilityMapping: String { get }
319 |
320 | /// *[Foundation]*
321 | /// Parses the `String` as a text representation of a
322 | /// property list, returning an NSString, NSData, NSArray, or
323 | /// NSDictionary object, according to the topmost element.
324 | public func propertyList() -> AnyObject
325 |
326 | /// *[Foundation]*
327 | /// Returns a dictionary object initialized with the keys and
328 | /// values found in the `String`.
329 | public func propertyListFromStringsFileFormat() -> [String : String]
330 |
331 | /// *[Foundation]*
332 | /// Finds and returns the range in the `String` of the first
333 | /// character from a given character set found in a given range with
334 | /// given options.
335 | public func rangeOfCharacter(from aSet: CharacterSet, options mask: CompareOptions = default, range aRange: Range? = default) -> Range?
336 |
337 | /// *[Foundation]*
338 | /// Returns the range in the `String` of the composed
339 | /// character sequence located at a given index.
340 | public func rangeOfComposedCharacterSequence(at anIndex: Index) -> Range
341 |
342 | /// *[Foundation]*
343 | /// Returns the range in the string of the composed character
344 | /// sequences for a given range.
345 | public func rangeOfComposedCharacterSequences(for range: Range) -> Range
346 |
347 | /// *[Foundation]*
348 | /// Finds and returns the range of the first occurrence of a
349 | /// given string within a given range of the `String`, subject to
350 | /// given options, using the specified locale, if any.
351 | public func range(of aString: String, options mask: CompareOptions = default, range searchRange: Range? = default, locale: Locale? = default) -> Range?
352 |
353 | /// *[Foundation]*
354 | /// Returns `true` if `self` contains `string`, taking the current locale
355 | /// into account.
356 | ///
357 | /// This is the most appropriate method for doing user-level string searches,
358 | /// similar to how searches are done generally in the system. The search is
359 | /// locale-aware, case and diacritic insensitive. The exact list of search
360 | /// options applied may change over time.
361 | public func localizedStandardContains(_ string: String) -> Bool
362 |
363 | /// *[Foundation]*
364 | /// Finds and returns the range of the first occurrence of a given string,
365 | /// taking the current locale into account. Returns `nil` if the string was
366 | /// not found.
367 | ///
368 | /// This is the most appropriate method for doing user-level string searches,
369 | /// similar to how searches are done generally in the system. The search is
370 | /// locale-aware, case and diacritic insensitive. The exact list of search
371 | /// options applied may change over time.
372 | public func localizedStandardRange(of string: String) -> Range?
373 |
374 | /// *[Foundation]*
375 | /// Returns the smallest encoding to which the `String` can
376 | /// be converted without loss of information.
377 | public var smallestEncoding: String.Encoding { get }
378 |
379 | /// *[Foundation]*
380 | /// Returns a new string made from the `String` by replacing
381 | /// all characters not in the specified set with percent encoded
382 | /// characters.
383 | public func addingPercentEncoding(withAllowedCharacters allowedCharacters: CharacterSet) -> String?
384 |
385 | /// *[Foundation]*
386 | /// Returns a representation of the `String` using a given
387 | /// encoding to determine the percent escapes necessary to convert
388 | /// the `String` into a legal URL string.
389 | @available(*, deprecated, message: "Use addingPercentEncoding(withAllowedCharacters:) instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.")
390 | public func addingPercentEscapes(using encoding: String.Encoding) -> String?
391 |
392 | /// *[Foundation]*
393 | /// Returns a string made by appending to the `String` a
394 | /// string constructed from a given format string and the following
395 | /// arguments.
396 | public func appendingFormat(_ format: String, _ arguments: CVarArg...) -> String
397 |
398 | /// *[Foundation]*
399 | /// Returns a new string made by appending a given string to
400 | /// the `String`.
401 | public func appending(_ aString: String) -> String
402 |
403 | /// *[Foundation]*
404 | /// Returns a string with the given character folding options
405 | /// applied.
406 | public func folding(_ options: CompareOptions = default, locale: Locale?) -> String
407 |
408 | /// *[Foundation]*
409 | /// Returns a new string formed from the `String` by either
410 | /// removing characters from the end, or by appending as many
411 | /// occurrences as necessary of a given pad string.
412 | public func padding(toLength newLength: Int, withPad padString: String, startingAt padIndex: Int) -> String
413 |
414 | /// *[Foundation]*
415 | /// Returns a new string made from the `String` by replacing
416 | /// all percent encoded sequences with the matching UTF-8
417 | /// characters.
418 | public var removingPercentEncoding: String? { get }
419 |
420 | /// *[Foundation]*
421 | /// Returns a new string in which the characters in a
422 | /// specified range of the `String` are replaced by a given string.
423 | public func replacingCharacters(in range: Range, with replacement: String) -> String
424 |
425 | /// *[Foundation]*
426 | /// Returns a new string in which all occurrences of a target
427 | /// string in a specified range of the `String` are replaced by
428 | /// another given string.
429 | public func replacingOccurrences(of target: String, with replacement: String, options: CompareOptions = default, range searchRange: Range? = default) -> String
430 |
431 | /// *[Foundation]*
432 | /// Returns a new string made by replacing in the `String`
433 | /// all percent escapes with the matching characters as determined
434 | /// by a given encoding.
435 | @available(*, deprecated, message: "Use removingPercentEncoding instead, which always uses the recommended UTF-8 encoding.")
436 | public func replacingPercentEscapes(using encoding: String.Encoding) -> String?
437 |
438 | /// *[Foundation]*
439 | /// Returns a new string made by removing from both ends of
440 | /// the `String` characters contained in a given character set.
441 | public func trimmingCharacters(in set: CharacterSet) -> String
442 |
443 | /// *[Foundation]*
444 | /// Returns a new string containing the characters of the
445 | /// `String` from the one at a given index to the end.
446 | public func substring(from index: Index) -> String
447 |
448 | /// *[Foundation]*
449 | /// Returns a new string containing the characters of the
450 | /// `String` up to, but not including, the one at a given index.
451 | public func substring(to index: Index) -> String
452 |
453 | /// *[Foundation]*
454 | /// Returns a string object containing the characters of the
455 | /// `String` that lie within a given range.
456 | public func substring(with aRange: Range) -> String
457 |
458 | /// *[Foundation]*
459 | /// An uppercase version of the string that is produced using the current
460 | /// locale.
461 | public var localizedUppercase: String { get }
462 |
463 | /// *[Foundation]*
464 | /// Returns a version of the string with all letters
465 | /// converted to uppercase, taking into account the specified
466 | /// locale.
467 | public func uppercased(with locale: Locale?) -> String
468 |
469 | /// *[Foundation]*
470 | /// Writes the contents of the `String` to a file at a given
471 | /// path using a given encoding.
472 | public func write(toFile path: String, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws
473 |
474 | /// *[Foundation]*
475 | /// Writes the contents of the `String` to the URL specified
476 | /// by url using the specified encoding.
477 | public func write(to url: URL, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws
478 |
479 | /// *[Foundation]*
480 | /// Perform string transliteration.
481 | public func applyingTransform(_ transform: StringTransform, reverse: Bool) -> String?
482 |
483 | /// *[Foundation]*
484 | /// Returns `true` iff `other` is non-empty and contained within
485 | /// `self` by case-sensitive, non-literal search.
486 | ///
487 | /// Equivalent to `self.rangeOfString(other) != nil`
488 | public func contains(_ other: String) -> Bool
489 |
490 | /// *[Foundation]*
491 | /// Returns `true` iff `other` is non-empty and contained within
492 | /// `self` by case-insensitive, non-literal search, taking into
493 | /// account the current locale.
494 | ///
495 | /// Locale-independent case-insensitive operation, and other needs,
496 | /// can be achieved by calling
497 | /// `rangeOfString(_:options:_, range:_locale:_)`.
498 | ///
499 | /// Equivalent to
500 | ///
501 | /// self.rangeOf(
502 | /// other, options: .CaseInsensitiveSearch,
503 | /// locale: Locale.current()) != nil
504 | public func localizedCaseInsensitiveContains(_ other: String) -> Bool
505 | }
506 |
507 | extension String {
508 | /// *[Foundation]*
509 | public init(_ cocoaString: NSString)
510 | }
511 |
512 | extension Bool {
513 | /// *[Foundation]*
514 | public init(_ number: NSNumber)
515 | }
516 |
517 | extension Double {
518 | /// *[Foundation]*
519 | public init(_ number: NSNumber)
520 | }
521 |
522 | extension UInt {
523 | /// *[Foundation]*
524 | public init(_ number: NSNumber)
525 | }
526 |
527 | extension String.UTF16View.Index : Strideable {
528 | /// *[Foundation]*
529 | /// Construct from an integer offset.
530 | public init(_ offset: Int)
531 |
532 | /// *[Foundation]*
533 | /// Returns a stride `x` such that `self.advanced(by: x)` approximates
534 | /// `other`.
535 | ///
536 | /// If `Stride` conforms to `Integer`, then `self.advanced(by: x) == other`.
537 | ///
538 | /// - Complexity: O(1).
539 | public func distance(to other: String.UTF16View.Index) -> Int
540 |
541 | /// *[Foundation]*
542 | /// Returns a `Self` `x` such that `self.distance(to: x)` approximates `n`.
543 | ///
544 | /// If `Stride` conforms to `Integer`, then `self.distance(to: x) == n`.
545 | ///
546 | /// - Complexity: O(1).
547 | public func advanced(by n: Int) -> String.UTF16View.Index
548 | }
549 |
550 | extension Float {
551 | /// *[Foundation]*
552 | public init(_ number: NSNumber)
553 | }
554 | extension Int {
555 | /// *[Foundation]*
556 | public init(_ number: NSNumber)
557 | }
558 |
559 |
--------------------------------------------------------------------------------
/test/data/ok.txt:
--------------------------------------------------------------------------------
1 | infix operator + {
2 | associativity left
3 | precedence 140
4 | }
5 |
6 | prefix operator ++ {
7 | }
8 |
9 | infix operator == {
10 | associativity none
11 | precedence 130
12 | }
13 |
14 | func +(lhs: Int, rhs: Int) -> Int
15 |
16 | func +(lhs: C, rhs: S) -> C
17 |
18 | func +(lhs: T.Stride, rhs: T) -> T
19 |
20 | func +(lhs: T, rhs: T.Stride) -> T
21 |
22 | prefix func ++(inout x: Int) -> Int
23 |
24 | func ==(lhs: Int, rhs: Int) -> Bool
25 |
26 | func ==(lhs: Bool, rhs: Bool) -> Bool
27 |
28 | /// Returns true if these arrays contain the same elements.
29 | func ==(lhs: [T], rhs: [T]) -> Bool
30 |
31 |
32 |
33 | /// The protocol to which all types implicitly conform
34 | typealias Any = protocol<>
35 |
36 |
37 | /// The protocol to which all class types implicitly conform.
38 | ///
39 | /// When used as a concrete type, all known `@objc` `class` methods and
40 | /// properties are available, as implicitly-unwrapped-optional methods
41 | /// and properties respectively, on each instance of `AnyClass`. For
42 | /// example:
43 | ///
44 | /// .. parsed-literal:
45 | ///
46 | /// class C {
47 | /// @objc class var cValue: Int { return 42 }
48 | /// }
49 | ///
50 | /// // If x has an @objc cValue: Int, return its value.
51 | /// // Otherwise, return nil.
52 | /// func getCValue(x: AnyClass) -> Int? {
53 | /// return **x.cValue**
54 | /// }
55 | ///
56 | /// See also: `AnyObject`
57 | typealias AnyClass = AnyObject.Type
58 |
59 |
60 | /// The protocol to which all classes implicitly conform.
61 | ///
62 | /// When used as a concrete type, all known `@objc` methods and
63 | /// properties are available, as implicitly-unwrapped-optional methods
64 | /// and properties respectively, on each instance of `AnyObject`. For
65 | /// example:
66 | ///
67 | /// .. parsed-literal:
68 | ///
69 | /// class C {
70 | /// @objc func getCValue() -> Int { return 42 }
71 | /// }
72 | ///
73 | /// // If x has a method @objc getValue()->Int, call it and
74 | /// // return the result. Otherwise, return nil.
75 | /// func getCValue1(x: AnyObject) -> Int? {
76 | /// if let f: ()->Int = **x.getCValue** {
77 | /// return f()
78 | /// }
79 | /// return nil
80 | /// }
81 | ///
82 | /// // A more idiomatic implementation using "optional chaining"
83 | /// func getCValue2(x: AnyObject) -> Int? {
84 | /// return **x.getCValue?()**
85 | /// }
86 | ///
87 | /// // An implementation that assumes the required method is present
88 | /// func getCValue3(x: AnyObject) -> **Int** {
89 | /// return **x.getCValue()** // x.getCValue is implicitly unwrapped.
90 | /// }
91 | ///
92 | /// See also: `AnyClass`
93 | @objc protocol AnyObject {
94 | }
95 |
96 |
97 | /// Conceptually_, `Array` is an efficient, tail-growable random-access
98 | /// collection of arbitrary elements.
99 | ///
100 | /// Common Properties of Array Types
101 | /// ================================
102 | ///
103 | /// The information in this section applies to all three of Swift's
104 | /// array types, `Array`, `ContiguousArray`, and `Slice`.
105 | /// When you read the word "array" here in a normal typeface, it
106 | /// applies to all three of them.
107 | ///
108 | /// Value Semantics
109 | /// ---------------
110 | ///
111 | /// Each array variable, `let` binding, or stored property has an
112 | /// independent value that includes the values of all of its elements.
113 | /// Therefore, mutations to the array are not observable through its
114 | /// copies::
115 | ///
116 | /// var a = [1, 2, 3]
117 | /// var b = a
118 | /// b[0] = 4
119 | /// println("a=\(a), b=\(b)") // a=[1, 2, 3], b=[4, 2, 3]
120 | ///
121 | /// (Of course, if the array stores `class` references, the objects
122 | /// are shared; only the values of the references are independent)
123 | ///
124 | /// Arrays use Copy-on-Write so that their storage and elements are
125 | /// only copied lazily, upon mutation, when more than one array
126 | /// instance is using the same buffer. Therefore, the first in any
127 | /// sequence of mutating operations may cost `O(N)` time and space,
128 | /// where `N` is the length of the array.
129 | ///
130 | /// Growth and Capacity
131 | /// -------------------
132 | ///
133 | /// When an array's contiguous storage fills up, new storage must be
134 | /// allocated and elements must be moved to the new storage. `Array`,
135 | /// `ContiguousArray`, and `Slice` share an exponential growth
136 | /// strategy that makes `append` a constant time operation *when
137 | /// amortized over many invocations*. In addition to a `count`
138 | /// property, these array types have a `capacity` that reflects their
139 | /// potential to store elements without reallocation, and when you
140 | /// know how many elements you'll store, you can call
141 | /// `reserveCapacity` to pre-emptively reallocate and prevent
142 | /// intermediate reallocations.
143 | ///
144 | /// .. _Conceptually:
145 | ///
146 | /// Objective-C Bridge
147 | /// ==================
148 | ///
149 | /// The main distinction between `Array` and the other array types is
150 | /// that it interoperates seamlessly and efficiently with Objective-C.
151 | ///
152 | /// `Array` is considered bridged to Objective-C iff `T` is bridged
153 | /// to Objective-C.
154 | ///
155 | /// When `T` is a `class` or `@objc` protocol type, `Array` may store
156 | /// its elements in an `NSArray`. Since any arbitrary subclass of
157 | /// `NSArray` can become an `Array`, there are no guarantees about
158 | /// representation or efficiency in this case (see also
159 | /// `ContiguousArray`). Since `NSArray` is immutable, it is just as
160 | /// though the storage was shared by some copy: the first in any
161 | /// sequence of mutating operations causes elements to be copied into
162 | /// unique, contiguous storage which may cost `O(N)` time and space,
163 | /// where `N` is the length of the array (or more, if the underlying
164 | /// `NSArray` is has unusual performance characteristics).
165 | ///
166 | /// Bridging to Objective-C
167 | /// -----------------------
168 | ///
169 | /// Any bridged `Array` can be implicitly converted to an `NSArray`.
170 | /// When `T` is a `class` or `@objc` protocol, bridging takes O(1)
171 | /// time and O(1) space. Other `Array`\ s must be bridged
172 | /// element-by-element, allocating a new object for each element, at a
173 | /// cost of at least O(`count`) time and space.
174 | ///
175 | /// Bridging from Objective-C
176 | /// -------------------------
177 | ///
178 | /// An `NSArray` can be implicitly or explicitly converted to any
179 | /// bridged `Array`. This conversion calls `copyWithZone` on the
180 | /// `NSArray`, to ensure it won't be modified, and stores the result
181 | /// in the `Array`. Type-checking, to ensure the `NSArray`\ 's
182 | /// elements match or can be bridged to `T`, is deferred until the
183 | /// first element access.
184 | struct Array : MutableCollectionType, Sliceable {
185 |
186 | /// The type of element stored by this `Array`
187 | typealias Element = T
188 |
189 | /// Always zero, which is the index of the first element when non-empty.
190 | var startIndex: Int { get }
191 |
192 | /// A "past-the-end" element index; the successor of the last valid
193 | /// subscript argument.
194 | var endIndex: Int { get }
195 | subscript (index: Int) -> T
196 |
197 | /// Return a *generator* over the elements.
198 | ///
199 | /// Complexity: O(1)
200 | func generate() -> IndexingGenerator<[T]>
201 |
202 | /// A type that can represent a sub-range of an `Array`
203 | typealias SubSlice = Slice
204 | subscript (subRange: Range) -> Slice
205 |
206 | /// Initialization from an existing buffer does not have "array.init"
207 | /// semantics because the caller may retain an alias to buffer.
208 | init(_ buffer: _ArrayBuffer)
209 | }
210 |
211 | extension Array : ArrayLiteralConvertible {
212 |
213 | /// Create an instance containing `elements`.
214 | init(arrayLiteral elements: T...)
215 | }
216 |
217 |
218 |
219 | extension Array {
220 |
221 | /// Construct an empty Array
222 | init()
223 |
224 | /// Construct from an arbitrary sequence with elements of type `T`
225 | init(_ s: S)
226 |
227 | /// Construct a Array of `count` elements, each initialized to
228 | /// `repeatedValue`.
229 | init(count: Int, repeatedValue: T)
230 |
231 | /// How many elements the Array stores
232 | var count: Int { get }
233 |
234 | /// How many elements the `Array` can store without reallocation
235 | var capacity: Int { get }
236 |
237 | /// `true` if and only if the `Array` is empty
238 | var isEmpty: Bool { get }
239 |
240 | /// The first element, or `nil` if the array is empty
241 | var first: T? { get }
242 |
243 | /// The last element, or `nil` if the array is empty
244 | var last: T? { get }
245 |
246 | /// Reserve enough space to store minimumCapacity elements.
247 | ///
248 | /// PostCondition: `capacity >= minimumCapacity` and the array has
249 | /// mutable contiguous storage.
250 | ///
251 | /// Complexity: O(`count`)
252 | mutating func reserveCapacity(minimumCapacity: Int)
253 |
254 | /// Append newElement to the Array
255 | ///
256 | /// Complexity: amortized O(1) unless `self`'s storage is shared with another live array; O(`count`) if `self` does not wrap a bridged `NSArray`; otherwise the efficiency is unspecified.
257 | mutating func append(newElement: T)
258 |
259 | /// Append the elements of `newElements` to `self`.
260 | ///
261 | /// Complexity: O(*length of result*)
262 | ///
263 | mutating func extend(newElements: S)
264 |
265 | /// Remove an element from the end of the Array in O(1).
266 | /// Requires: count > 0
267 | mutating func removeLast() -> T
268 |
269 | /// Insert `newElement` at index `i`.
270 | ///
271 | /// Requires: `i <= count`
272 | ///
273 | /// Complexity: O(\ `count`\ ).
274 | mutating func insert(newElement: T, atIndex i: Int)
275 |
276 | /// Remove and return the element at index `i`
277 | ///
278 | /// Invalidates all indices with respect to `self`.
279 | ///
280 | /// Complexity: O(\ `count`\ ).
281 | mutating func removeAtIndex(index: Int) -> T
282 |
283 | /// Remove all elements.
284 | ///
285 | /// Postcondition: `capacity == 0` iff `keepCapacity` is `false`.
286 | ///
287 | /// Complexity: O(\ `countElements(self)`\ ).
288 | mutating func removeAll(keepCapacity: Bool = default)
289 |
290 | /// Interpose `self` between each consecutive pair of `elements`,
291 | /// and concatenate the elements of the resulting sequence. For
292 | /// example, `[-1, -2].join([[1, 2, 3], [4, 5, 6], [7, 8, 9]])`
293 | /// yields `[1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]`
294 | func join(elements: S) -> [T]
295 |
296 | /// Return the result of repeatedly calling `combine` with an
297 | /// accumulated value initialized to `initial` and each element of
298 | /// `self`, in turn, i.e. return
299 | /// `combine(combine(...combine(combine(initial, self[0]),
300 | /// self[1]),...self[count-2]), self[count-1])`.
301 | func reduce(initial: U, combine: (U, T) -> U) -> U
302 |
303 | /// Sort `self` in-place according to `isOrderedBefore`. Requires:
304 | /// `isOrderedBefore` induces a `strict weak ordering
305 | /// `__
306 | /// over the elements.
307 | mutating func sort(isOrderedBefore: (T, T) -> Bool)
308 |
309 | /// Return a copy of `self` that has been sorted according to
310 | /// `isOrderedBefore`. Requires: `isOrderedBefore` induces a
311 | /// `strict weak ordering
312 | /// `__
313 | /// over the elements.
314 | func sorted(isOrderedBefore: (T, T) -> Bool) -> [T]
315 |
316 | /// Return an `Array` containing the results of calling
317 | /// `transform(x)` on each element `x` of `self`
318 | func map(transform: (T) -> U) -> [U]
319 |
320 | /// A Array containing the elements of `self` in reverse order
321 | func reverse() -> [T]
322 |
323 | /// Return an `Array` containing the elements `x` of `self` for which
324 | /// `includeElement(x)` is `true`
325 | func filter(includeElement: (T) -> Bool) -> [T]
326 | }
327 |
328 |
329 |
330 | /// Conforming types can be initialized with array literals
331 | protocol ArrayLiteralConvertible {
332 | typealias Element
333 |
334 | /// Create an instance initialized with `elements`.
335 | init(arrayLiteral elements: Element...)
336 | }
337 |
338 |
339 | /// An *index* that can step backwards via application of its
340 | /// `predecessor()` method.
341 | protocol BidirectionalIndexType : ForwardIndexType, _BidirectionalIndexType {
342 | }
343 |
344 |
345 | /// A value type whose instances are either `true` or `false`.
346 | struct Bool {
347 |
348 | /// Default-initialize Boolean value to `false`.
349 | init()
350 | }
351 |
352 | extension Bool : Equatable, Hashable {
353 |
354 | /// The hash value.
355 | ///
356 | /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
357 | ///
358 | /// **Note:** the hash value is not guaranteed to be stable across
359 | /// different invocations of the same program. Do not persist the
360 | /// hash value across program runs.
361 | var hashValue: Int { get }
362 | }
363 |
364 | extension Bool : Reflectable {
365 |
366 | /// Returns a mirror that reflects `self`.
367 | func getMirror() -> MirrorType
368 | }
369 |
370 |
371 | /// The C '_Bool' and C++ 'bool' type.
372 | typealias CBool = Bool
373 |
374 | /// The C 'long' type.
375 | typealias CLong = Int
376 |
377 |
378 | /// A multi-pass *sequence* with addressable positions.
379 | ///
380 | /// Positions are represented by an associated `Index` type. Whereas
381 | /// an arbitrary *sequence* may be consumed as it is traversed, a
382 | /// *collection* is multi-pass: any element may be revisited merely by
383 | /// saving its index.
384 | ///
385 | /// The sequence view of the elements is identical to the collection
386 | /// view. In other words, the following code binds the same series of
387 | /// values to `x` as does `for x in self {}`::
388 | ///
389 | /// for i in startIndex.. Self.Generator.Element { get }
394 | }
395 |
396 |
397 | /// Instances of conforming types can be compared for value equality
398 | /// using operators `==` and `!=`.
399 | ///
400 | /// When adopting `Equatable`, only the `==` operator is required to be
401 | /// implemented. The standard library provides an implementation for `!=`.
402 | protocol Equatable {
403 |
404 | /// Return true if `lhs` is equal to `rhs`.
405 | ///
406 | /// **Equality implies substitutability**. When `x == y`, `x` and
407 | /// `y` are interchangeable in any code that only depends on their
408 | /// values.
409 | ///
410 | /// Class instance identity as distinguished by triple-equals `===`
411 | /// is notably not part of an instance's value. Exposing other
412 | /// non-value aspects of `Equatable` types is discouraged, and any
413 | /// that *are* exposed should be explicitly pointed out in
414 | /// documentation.
415 | ///
416 | /// **Equality is an equivalence relation**
417 | ///
418 | /// - `x == x` is `true`
419 | /// - `x == y` implies `y == x`
420 | /// - `x == y` and `y == z` implies `x == z`
421 | ///
422 | /// **Inequality is the inverse of equality**, i.e. `!(x == y)` iff
423 | /// `x != y`
424 | func ==(lhs: Self, rhs: Self) -> Bool
425 | }
426 |
427 | /// A collection type that can be efficiently appended-to.
428 | protocol ExtensibleCollectionType : _ExtensibleCollectionType {
429 | }
430 |
431 |
432 | /// Represents a discrete value in a series, where a value's
433 | /// successor, if any, is reachable by applying the value's
434 | /// `successor()` method.
435 | protocol ForwardIndexType : _ForwardIndexType {
436 | }
437 |
438 |
439 | /// Encapsulates iteration state and interface for iteration over a
440 | /// *sequence*.
441 | ///
442 | /// **Note:** While it is safe to copy a *generator*, advancing one
443 | /// copy may invalidate the others.
444 | ///
445 | /// Any code that uses multiple generators (or `for`\ ...\ `in` loops)
446 | /// over a single *sequence* should have static knowledge that the
447 | /// specific *sequence* is multi-pass, either because its concrete
448 | /// type is known or because it is constrained to `CollectionType`.
449 | /// Also, the generators must be obtained by distinct calls to the
450 | /// *sequence's* `generate()` method, rather than by copying.
451 | protocol GeneratorType {
452 |
453 | /// The type of element generated by `self`.
454 | typealias Element
455 |
456 | /// Advance to the next element and return it, or `nil` if no next
457 | /// element exists.
458 | ///
459 | /// Requires: `next()` has not been applied to a copy of `self`
460 | /// since the copy was made, and no preceding call to `self.next()`
461 | /// has returned `nil`. Specific implementations of this protocol
462 | /// are encouraged to respond to violations of this requirement by
463 | /// calling `preconditionFailure("...")`.
464 | mutating func next() -> Element?
465 | }
466 |
467 |
468 | /// Instances of conforming types provide an integer `hashValue` and
469 | /// can be used as `Dictionary` keys.
470 | protocol Hashable : Equatable {
471 |
472 | /// The hash value.
473 | ///
474 | /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
475 | ///
476 | /// **Note:** the hash value is not guaranteed to be stable across
477 | /// different invocations of the same program. Do not persist the
478 | /// hash value across program runs.
479 | var hashValue: Int { get }
480 | }
481 |
482 |
483 |
484 | /// A 64-bit signed integer value
485 | /// type.
486 | struct Int : SignedIntegerType {
487 | var value: Builtin.Word
488 |
489 | /// A type that can represent the number of steps between pairs of
490 | /// values.
491 | typealias Distance = Int
492 |
493 | /// Create an instance initialized to zero.
494 | init()
495 |
496 | /// Create an instance initialized to `value`.
497 | init(_ value: Int)
498 |
499 | /// Creates an integer from its big-endian representation, changing the
500 | /// byte order if necessary.
501 | init(bigEndian value: Int)
502 |
503 | /// Creates an integer from its little-endian representation, changing the
504 | /// byte order if necessary.
505 | init(littleEndian value: Int)
506 | init(_builtinIntegerLiteral value: Builtin.Int2048)
507 |
508 | /// Create an instance initialized to `value`.
509 | init(integerLiteral value: Int)
510 |
511 | /// Returns the big-endian representation of the integer, changing the
512 | /// byte order if necessary.
513 | var bigEndian: Int { get }
514 |
515 | /// Returns the little-endian representation of the integer, changing the
516 | /// byte order if necessary.
517 | var littleEndian: Int { get }
518 |
519 | /// Returns the current integer with the byte order swapped.
520 | var byteSwapped: Int { get }
521 | static var max: Int { get }
522 | static var min: Int { get }
523 | }
524 |
525 | extension Int : Hashable {
526 |
527 | /// The hash value.
528 | ///
529 | /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
530 | ///
531 | /// **Note:** the hash value is not guaranteed to be stable across
532 | /// different invocations of the same program. Do not persist the
533 | /// hash value across program runs.
534 | var hashValue: Int { get }
535 | }
536 |
537 | extension Int : RandomAccessIndexType {
538 |
539 | /// Returns the next consecutive value after `self`.
540 | ///
541 | /// Requires: the next value is representable.
542 | func successor() -> Int
543 |
544 | /// Returns the previous consecutive value before `self`.
545 | ///
546 | /// Requires: the previous value is representable.
547 | func predecessor() -> Int
548 |
549 | /// Return the minimum number of applications of `successor` or
550 | /// `predecessor` required to reach `other` from `self`.
551 | ///
552 | /// Complexity: O(1).
553 | func distanceTo(other: Int) -> Distance
554 |
555 | /// Return `self` offset by `n` steps.
556 | ///
557 | /// :returns: If `n > 0`, the result of applying `successor` to
558 | /// `self` `n` times. If `n < 0`, the result of applying
559 | /// `predecessor` to `self` `-n` times. Otherwise, `self`.
560 | ///
561 | /// Complexity: O(1)
562 | func advancedBy(amount: Distance) -> Int
563 | }
564 |
565 | extension Int {
566 |
567 | /// Add `lhs` and `rhs`, returning a result and a
568 | /// `Bool` that is true iff the operation caused an arithmetic
569 | /// overflow.
570 | static func addWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
571 |
572 | /// Subtract `lhs` and `rhs`, returning a result and a
573 | /// `Bool` that is true iff the operation caused an arithmetic
574 | /// overflow.
575 | static func subtractWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
576 |
577 | /// Multiply `lhs` and `rhs`, returning a result and a
578 | /// `Bool` that is true iff the operation caused an arithmetic
579 | /// overflow.
580 | static func multiplyWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
581 |
582 | /// Divide `lhs` and `rhs`, returning
583 | /// a result and a `Bool`
584 | /// that is true iff the operation caused an arithmetic overflow.
585 | static func divideWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
586 |
587 | /// Divide `lhs` and `rhs`, returning
588 | /// the remainder and a `Bool`
589 | /// that is true iff the operation caused an arithmetic overflow.
590 | static func remainderWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
591 |
592 | /// Represent this number using Swift's widest native signed
593 | /// integer type.
594 | func toIntMax() -> IntMax
595 | }
596 |
597 | extension Int {
598 | init(_ v: UInt8)
599 | init(_ v: Int8)
600 | init(_ v: UInt16)
601 | init(_ v: Int16)
602 | init(_ v: UInt32)
603 | init(_ v: Int32)
604 | init(_ v: UInt64)
605 |
606 | /// Construct a `Int` having the same bitwise representation as
607 | /// the least significant bits of the provided bit pattern.
608 | ///
609 | /// No range or overflow checking occurs.
610 | init(truncatingBitPattern: UInt64)
611 | init(_ v: Int64)
612 |
613 | /// Construct a `Int` having the same bitwise representation as
614 | /// the least significant bits of the provided bit pattern.
615 | ///
616 | /// No range or overflow checking occurs.
617 | init(truncatingBitPattern: Int64)
618 | init(_ v: UInt)
619 |
620 | /// Construct a `Int` having the same memory representation as
621 | /// the `UInt` `bitPattern`. No range or overflow checking
622 | /// occurs, and the resulting `Int` may not have the same numeric
623 | /// value as `bitPattern`--it is only guaranteed to use the same
624 | /// pattern of bits.
625 | init(bitPattern: UInt)
626 | }
627 |
628 | extension Int : Reflectable {
629 |
630 | /// Returns a mirror that reflects `self`.
631 | func getMirror() -> MirrorType
632 | }
633 |
634 |
635 | /// The common requirements for types that support integer arithmetic.
636 | protocol IntegerArithmeticType : _IntegerArithmeticType {
637 |
638 | /// Add `lhs` and `rhs`, returning a result and trapping in case of
639 | /// arithmetic overflow (except in -Ounchecked builds).
640 | func +(lhs: Self, rhs: Self) -> Self
641 |
642 | }
643 |
644 |
645 | /// Conforming types can be initialized with integer literals
646 | protocol IntegerLiteralConvertible {
647 | typealias IntegerLiteralType
648 |
649 | /// Create an instance initialized to `value`.
650 | init(integerLiteral value: IntegerLiteralType)
651 | }
652 |
653 |
654 | /// The default type for an otherwise-unconstrained integer literal
655 | typealias IntegerLiteralType = Int
656 |
657 |
658 | /// A set of common requirements for Swift's integer types.
659 | protocol IntegerType : _IntegerType, RandomAccessIndexType {
660 | }
661 |
662 |
663 | /// An interval over a `Comparable` type.
664 | protocol IntervalType {
665 |
666 | /// The type of the `Interval`\ 's endpoints
667 | typealias Bound : Comparable
668 |
669 | /// Returns `true` iff the interval contains `value`
670 | func contains(value: Bound) -> Bool
671 |
672 | /// Return `rhs` clamped to `self`. The bounds of the result, even
673 | /// if it is empty, are always within the bounds of `self`
674 | func clamp(intervalToClamp: Self) -> Self
675 |
676 | /// True iff `self` is empty
677 | var isEmpty: Bool { get }
678 |
679 | /// The `Interval`\ 's lower bound. Invariant: `start` <= `end`
680 | var start: Bound { get }
681 |
682 | /// The `Interval`\ 's upper bound. Invariant: `start` <= `end`
683 | var end: Bound { get }
684 | }
685 |
686 |
687 | /// How children of this value should be presented in the IDE.
688 | enum MirrorDisposition {
689 | case Struct
690 | case Class
691 | case Enum
692 | case Tuple
693 | case Aggregate
694 | case IndexContainer
695 | case KeyContainer
696 | case MembershipContainer
697 | case Container
698 | case Optional
699 | case ObjCObject
700 | }
701 |
702 |
703 | /// The type returned by `reflect(x)`; supplies an API for runtime
704 | /// reflection on `x`
705 | protocol MirrorType {
706 |
707 | /// The instance being reflected
708 | var value: Any { get }
709 |
710 | /// Identical to `value.dynamicType`
711 | var valueType: Any.Type { get }
712 |
713 | /// A unique identifier for `value` if it is a class instance; `nil`
714 | /// otherwise.
715 | var objectIdentifier: ObjectIdentifier? { get }
716 |
717 | /// The count of `value`\ 's logical children
718 | var count: Int { get }
719 | subscript (i: Int) -> (String, MirrorType) { get }
720 |
721 | /// A string description of `value`.
722 | var summary: String { get }
723 |
724 | /// A rich representation of `value` for an IDE, or `nil` if none is supplied.
725 | var quickLookObject: QuickLookObject? { get }
726 |
727 | /// How `value` should be presented in an IDE.
728 | var disposition: MirrorDisposition { get }
729 | }
730 |
731 |
732 | /// A *collection* that supports subscript assignment.
733 | ///
734 | /// For any instance `a` of a type conforming to
735 | /// `MutableCollectionType`, ::
736 | ///
737 | /// a[i] = x
738 | /// let y = a[i]
739 | ///
740 | /// is equivalent to ::
741 | ///
742 | /// a[i] = x
743 | /// let y = x
744 | ///
745 | protocol MutableCollectionType : CollectionType {
746 | subscript (position: Self.Index) -> Self.Generator.Element { get set }
747 | }
748 |
749 |
750 | /// A *collection* with mutable slices.
751 | ///
752 | /// For example,
753 | ///
754 | /// .. parsed-literal:
755 | ///
756 | /// x[i..) -> Self.SubSlice { get set }
760 | }
761 |
762 |
763 | /// An instance that exposes API for interaction with processes
764 | let Process: _Process
765 |
766 |
767 | /// The sum of types that can be used as a quick look representation.
768 | ///
769 | /// This type must be binary-compatible with the 'QuickLookObject' struct in
770 | /// stdlib/Runtime/Reflection.mm, and 'QuickLookObject?' must be binary
771 | /// compatible with 'OptionalQuickLookObject' from the same.
772 | ///
773 | /// NB: This type is somewhat carefully laid out to *suppress* enum layout
774 | /// optimization so that it is easier to manufacture in the C++ runtime
775 | /// implementation.
776 | enum QuickLookObject {
777 | case Text(String)
778 | case Int(Int64)
779 | case UInt(UInt64)
780 | case Float(Double)
781 | case Image(Any)
782 | case Sound(Any)
783 | case Color(Any)
784 | case BezierPath(Any)
785 | case AttributedString(Any)
786 | case Rectangle(Double, Double, Double, Double)
787 | case Point(Double, Double)
788 | case Size(Double, Double)
789 | case Logical(Bool)
790 | case Range(UInt64, UInt64)
791 | case View(Any)
792 | case Sprite(Any)
793 | case URL(String)
794 | }
795 |
796 |
797 | /// An *index* that can be offset by an arbitrary number of positions,
798 | /// and can measure the distance to any reachable value, in O(1).
799 | protocol RandomAccessIndexType : BidirectionalIndexType, _RandomAccessIndexType {
800 | }
801 |
802 |
803 | /// A *collection* that supports replacement of an arbitrary subRange
804 | /// of elements with the elements of another collection.
805 | protocol RangeReplaceableCollectionType : ExtensibleCollectionType {
806 |
807 | /// Replace the given `subRange` of elements with `newElements`.
808 | ///
809 | /// Invalidates all indices with respect to `self`.
810 | ///
811 | /// Complexity: O(\ `countElements(subRange)`\ ) if
812 | /// `subRange.endIndex == self.endIndex` and `isEmpty(newElements)`\ ,
813 | /// O(\ `countElements(self)`\ + \`countElements(newElements)`\ ) otherwise.
814 | mutating func replaceRange(subRange: Range, with newElements: C)
815 |
816 | /// Insert `newElement` at index `i`.
817 | ///
818 | /// Invalidates all indices with respect to `self`.
819 | ///
820 | /// Complexity: O(\ `countElements(self)`\ ).
821 | ///
822 | /// Can be implemented as::
823 | ///
824 | /// Swift.insert(&self, newElement, atIndex: i)
825 | mutating func insert(newElement: Self.Generator.Element, atIndex i: Self.Index)
826 |
827 | /// Insert `newElements` at index `i`
828 | ///
829 | /// Invalidates all indices with respect to `self`.
830 | ///
831 | /// Complexity: O(\ `countElements(self) + countElements(newElements)`\ ).
832 | ///
833 | /// Can be implemented as::
834 | ///
835 | /// Swift.splice(&self, newElements, atIndex: i)
836 | mutating func splice(newElements: S, atIndex i: Self.Index)
837 |
838 | /// Remove the element at index `i`
839 | ///
840 | /// Invalidates all indices with respect to `self`.
841 | ///
842 | /// Complexity: O(\ `countElements(self)`\ ).
843 | ///
844 | /// Can be implemented as::
845 | ///
846 | /// Swift.removeAtIndex(&self, i)
847 | mutating func removeAtIndex(i: Self.Index) -> Self.Generator.Element
848 |
849 | /// Remove the indicated `subRange` of elements
850 | ///
851 | /// Invalidates all indices with respect to `self`.
852 | ///
853 | /// Complexity: O(\ `countElements(self)`\ ).
854 | ///
855 | /// Can be implemented as::
856 | ///
857 | /// Swift.removeRange(&self, subRange)
858 | mutating func removeRange(subRange: Range)
859 |
860 | /// Remove all elements
861 | ///
862 | /// Invalidates all indices with respect to `self`.
863 | ///
864 | /// :param: `keepCapacity`, if `true`, is a non-binding request to
865 | /// avoid releasing storage, which can be a useful optimization
866 | /// when `self` is going to be grown again.
867 | ///
868 | /// Complexity: O(\ `countElements(self)`\ ).
869 | ///
870 | /// Can be implemented as::
871 | ///
872 | /// Swift.removeAll(&self, keepCapacity: keepCapacity)
873 | mutating func removeAll(#keepCapacity: Bool)
874 | }
875 |
876 |
877 | /// Customizes the result of `reflect(x)`, where `x` is a conforming
878 | /// type.
879 | protocol Reflectable {
880 |
881 | /// Returns a mirror that reflects `self`.
882 | func getMirror() -> MirrorType
883 | }
884 |
885 | /// A type that can be iterated with a `for`\ ...\ `in` loop.
886 | ///
887 | /// `SequenceType` makes no requirement on conforming types regarding
888 | /// whether they will be destructively "consumed" by iteration. To
889 | /// ensure non-destructive iteration, constrain your *sequence* to
890 | /// `CollectionType`.
891 | protocol SequenceType : _Sequence_Type {
892 |
893 | /// A type that provides the *sequence*\ 's iteration interface and
894 | /// encapsulates its iteration state.
895 | typealias Generator : GeneratorType
896 |
897 | /// Return a *generator* over the elements of this *sequence*.
898 | ///
899 | /// Complexity: O(1)
900 | func generate() -> Generator
901 | }
902 |
903 | /// A set of common requirements for Swift's signed integer types.
904 | protocol SignedIntegerType : _SignedIntegerType, IntegerType {
905 | }
906 |
907 | /// A *collection* from which a sub-range of elements (a "slice")
908 | /// can be efficiently extracted.
909 | protocol Sliceable : _Sliceable {
910 |
911 | /// The *collection* type that represents a sub-range of elements.
912 | ///
913 | /// Though it can't currently be enforced by the type system, the
914 | /// `SubSlice` type in a concrete implementation of `Sliceable`
915 | /// should also be `Sliceable`.
916 | typealias SubSlice : _Sliceable
917 | subscript (bounds: Range) -> SubSlice { get }
918 | }
919 |
920 |
921 | /// Conforming types are notionally continuous, one-dimensional
922 | /// values that can be offset and measured.
923 | ///
924 | /// See also: `stride(from: to: by:)` and `stride(from: through: by:)`
925 | protocol Strideable : _Strideable {
926 | }
927 |
928 |
929 | /// The empty tuple type.
930 | ///
931 | /// This is the default return type of functions for which no explicit
932 | /// return type is specified.
933 | typealias Void = ()
934 |
935 |
936 | /// A signed integer type that occupies one machine word
937 | typealias Word = Int
938 |
939 |
940 | /// This protocol is an implementation detail of `BidirectionalIndexType`; do
941 | /// not use it directly.
942 | ///
943 | /// Its requirements are inherited by `BidirectionalIndexType` and thus must
944 | /// be satisfied by types conforming to that protocol.
945 | protocol _BidirectionalIndexType : _ForwardIndexType {
946 |
947 | /// Return the previous consecutive value in a discrete sequence.
948 | ///
949 | /// If `self` has a well-defined successor,
950 | /// `self.successor().predecessor() == self`. If `self` has a
951 | /// well-defined predecessor, `self.predecessor().successor() ==
952 | /// self`.
953 | ///
954 | /// Requires: `self` has a well-defined predecessor.
955 | func predecessor() -> Self
956 | }
957 |
958 |
959 | /// This protocol is an implementation detail of `CollectionType`; do
960 | /// not use it directly.
961 | ///
962 | /// Its requirements are inherited by `CollectionType` and thus must
963 | /// be satisfied by types conforming to that protocol.
964 | protocol _CollectionType : _SequenceType {
965 |
966 | /// A type that represents a valid position in the collection.
967 | ///
968 | /// Valid indices consist of the position of every element and a
969 | /// "past the end" position that's not valid for use as a subscript.
970 | typealias Index : ForwardIndexType
971 |
972 | /// The position of the first element in a non-empty collection.
973 | ///
974 | /// Identical to `endIndex` in an empty collection.
975 | var startIndex: Index { get }
976 |
977 | /// The collection's "past the end" position.
978 | ///
979 | /// `endIndex` is not a valid argument to `subscript`, and is always
980 | /// reachable from `startIndex` by zero or more applications of
981 | /// `successor()`.
982 | var endIndex: Index { get }
983 | typealias _Element
984 | subscript (_i: Index) -> _Element { get }
985 | }
986 |
987 |
988 |
989 | /// This protocol is an implementation detail of `ExtensibleCollectionType`; do
990 | /// not use it directly.
991 | ///
992 | /// Its requirements are inherited by `ExtensibleCollectionType` and thus must
993 | /// be satisfied by types conforming to that protocol.
994 | protocol _ExtensibleCollectionType : CollectionType {
995 |
996 | /// Create an empty instance
997 | init()
998 |
999 | /// A non-binding request to ensure `n` elements of available storage.
1000 | ///
1001 | /// This works as an optimization to avoid multiple reallocations of
1002 | /// linear data structures like `Array`. Conforming types may
1003 | /// reserve more than `n`, exactly `n`, less than `n` elements of
1004 | /// storage, or even ignore the request completely.
1005 | mutating func reserveCapacity(n: Self.Index.Distance)
1006 |
1007 | /// Append `x` to `self`.
1008 | ///
1009 | /// Applying `successor()` to the index of the new element yields
1010 | /// `self.endIndex`.
1011 | ///
1012 | /// Complexity: amortized O(1).
1013 | mutating func append(x: Self.Generator.Element)
1014 |
1015 | /// Append the elements of `newElements` to `self`.
1016 | ///
1017 | /// Complexity: O(*length of result*)
1018 | ///
1019 | /// A possible implementation::
1020 | ///
1021 | /// reserveCapacity(countElements(self) + underestimateCount(newElements))
1022 | /// for x in newElements {
1023 | /// newElements.append(x)
1024 | /// }
1025 | mutating func extend(newElements: S)
1026 | }
1027 |
1028 |
1029 | /// This protocol is an implementation detail of `ForwardIndexType`; do
1030 | /// not use it directly.
1031 | ///
1032 | /// Its requirements are inherited by `ForwardIndexType` and thus must
1033 | /// be satisfied by types conforming to that protocol.
1034 | protocol _ForwardIndexType : _Incrementable {
1035 |
1036 | /// A type that can represent the number of steps between pairs of
1037 | /// `Self` values where one value is reachable from the other.
1038 | ///
1039 | /// Reachability is defined by the ability to produce one value from
1040 | /// the other via zero or more applications of `successor`.
1041 | typealias Distance : _SignedIntegerType = Int
1042 | typealias _DisabledRangeIndex = _DisabledRangeIndex_
1043 | }
1044 |
1045 |
1046 | /// This protocol is an implementation detail of `ForwardIndexType`; do
1047 | /// not use it directly.
1048 | ///
1049 | /// Its requirements are inherited by `ForwardIndexType` and thus must
1050 | /// be satisfied by types conforming to that protocol.
1051 | protocol _Incrementable : Equatable {
1052 |
1053 | /// Return the next consecutive value in a discrete sequence of
1054 | /// `Self` values
1055 | ///
1056 | /// Requires: `self` has a well-defined successor.
1057 | func successor() -> Self
1058 | }
1059 |
1060 |
1061 | /// This protocol is an implementation detail of `IntegerArithmeticType`; do
1062 | /// not use it directly.
1063 | ///
1064 | /// Its requirements are inherited by `IntegerArithmeticType` and thus must
1065 | /// be satisfied by types conforming to that protocol.
1066 | protocol _IntegerArithmeticType {
1067 |
1068 | /// Add `lhs` and `rhs`, returning a result and a `Bool` that is
1069 | /// true iff the operation caused an arithmetic overflow.
1070 | class func addWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1071 |
1072 | /// Subtract `lhs` and `rhs`, returning a result and a `Bool` that is
1073 | /// true iff the operation caused an arithmetic overflow.
1074 | class func subtractWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1075 |
1076 | /// Multiply `lhs` and `rhs`, returning a result and a `Bool` that is
1077 | /// true iff the operation caused an arithmetic overflow.
1078 | class func multiplyWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1079 |
1080 | /// Divide `lhs` and `rhs`, returning a result and a `Bool` that is
1081 | /// true iff the operation caused an arithmetic overflow.
1082 | class func divideWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1083 |
1084 | /// Divide `lhs` and `rhs`, returning the remainder and a `Bool` that is
1085 | /// true iff the operation caused an arithmetic overflow.
1086 | class func remainderWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1087 | }
1088 |
1089 |
1090 | /// This protocol is an implementation detail of `IntegerType`; do
1091 | /// not use it directly.
1092 | ///
1093 | /// Its requirements are inherited by `IntegerType` and thus must
1094 | /// be satisfied by types conforming to that protocol.
1095 | protocol _IntegerType : IntegerLiteralConvertible, Hashable, IntegerArithmeticType, _Incrementable {
1096 | }
1097 |
1098 |
1099 | /// This protocol is an implementation detail of `RandomAccessIndexType`; do
1100 | /// not use it directly.
1101 | ///
1102 | /// Its requirements are inherited by `RandomAccessIndexType` and thus must
1103 | /// be satisfied by types conforming to that protocol.
1104 | protocol _RandomAccessIndexType : _BidirectionalIndexType, Strideable {
1105 |
1106 | /// Return the minimum number of applications of `successor` or
1107 | /// `predecessor` required to reach `other` from `self`.
1108 | ///
1109 | /// Complexity: O(1).
1110 | ///
1111 | /// Axioms::
1112 | ///
1113 | /// x.distanceTo(x.successor())) == 1
1114 | /// x.distanceTo(x.predecessor())) == -1
1115 | /// x.advancedBy(x.distanceTo(y)) == y
1116 | func distanceTo(other: Self) -> Self.Distance
1117 |
1118 | /// Return `self` offset by `n` steps.
1119 | ///
1120 | /// :returns: If `n > 0`, the result of applying `successor` to
1121 | /// `self` `n` times. If `n < 0`, the result of applying
1122 | /// `predecessor` to `self` `-n` times. Otherwise, `self`.
1123 | ///
1124 | /// Complexity: O(1)
1125 | ///
1126 | /// Axioms::
1127 | ///
1128 | /// x.advancedBy(0) == x
1129 | /// x.advancedBy(1) == x.successor()
1130 | /// x.advancedBy(-1) == x.predecessor()
1131 | /// x.distanceTo(x.advancedBy(m)) == m
1132 | func advancedBy(n: Self.Distance) -> Self
1133 | }
1134 |
1135 |
1136 | /// This protocol is an implementation detail of `SequenceType`; do
1137 | /// not use it directly.
1138 | ///
1139 | /// Its requirements are inherited by `SequenceType` and thus must
1140 | /// be satisfied by types conforming to that protocol.
1141 | protocol _SequenceType {
1142 | }
1143 |
1144 |
1145 | /// This protocol is an implementation detail of `SequenceType`; do
1146 | /// not use it directly.
1147 | ///
1148 | /// Its requirements are inherited by `SequenceType` and thus must
1149 | /// be satisfied by types conforming to that protocol.
1150 | protocol _Sequence_Type : _SequenceType {
1151 |
1152 | /// A type whose instances can produce the elements of this
1153 | /// sequence, in order.
1154 | typealias Generator : GeneratorType
1155 |
1156 | /// Return a *generator* over the elements of this *sequence*. The
1157 | /// *generator*\ 's next element is the first element of the
1158 | /// sequence.
1159 | ///
1160 | /// Complexity: O(1)
1161 | func generate() -> Generator
1162 | }
1163 |
1164 |
1165 | /// This protocol is an implementation detail of `SignedIntegerType`;
1166 | /// do not use it directly.
1167 | ///
1168 | /// Its requirements are inherited by `SignedIntegerType` and thus
1169 | /// must be satisfied by types conforming to that protocol.
1170 | protocol _SignedIntegerType : _IntegerType {
1171 |
1172 | /// Represent this number using Swift's widest native signed integer
1173 | /// type.
1174 | func toIntMax() -> IntMax
1175 |
1176 | /// Convert from Swift's widest signed integer type, trapping on
1177 | /// overflow.
1178 | init(_: IntMax)
1179 | }
1180 |
1181 |
1182 | /// This protocol is an implementation detail of `Sliceable`; do
1183 | /// not use it directly.
1184 | ///
1185 | /// Its requirements are inherited by `Sliceable` and thus must
1186 | /// be satisfied by types conforming to that protocol.
1187 | protocol _Sliceable : CollectionType {
1188 | }
1189 |
1190 |
1191 | /// This protocol is an implementation detail of `Strideable`; do
1192 | /// not use it directly.
1193 | ///
1194 | /// Its requirements are inherited by `Strideable` and thus must
1195 | /// be satisfied by types conforming to that protocol.
1196 | protocol _Strideable {
1197 |
1198 | /// A type that can represent the distance between two values of `Self`
1199 | typealias Stride : SignedNumberType
1200 |
1201 | /// Returns a stride `x` such that `self.advancedBy(x)` approximates
1202 | /// `other`.
1203 | ///
1204 | /// Complexity: O(1).
1205 | ///
1206 | /// See also: `RandomAccessIndexType`\ 's `distanceTo`, which provides a
1207 | /// stronger semantic guarantee.
1208 | func distanceTo(other: Self) -> Stride
1209 |
1210 | /// Returns a `Self` `x` such that `self.distanceTo(x)` approximates
1211 | /// `n`.
1212 | ///
1213 | /// Complexity: O(1).
1214 | ///
1215 | /// See also: `RandomAccessIndexType`\ 's `advancedBy`, which
1216 | /// provides a stronger semantic guarantee.
1217 | func advancedBy(n: Stride) -> Self
1218 | }
1219 |
1220 |
1221 | /// Return the result of advancing `start` by `n` positions. If `T`
1222 | /// models `RandomAccessIndexType`, executes in O(1). Otherwise,
1223 | /// executes in O(`abs(n)`). If `T` does not model
1224 | /// `BidirectionalIndexType`, requires that `n` is non-negative.
1225 | ///
1226 | /// `advance(i, n)` is a synonym for `i++n'
1227 | func advance(start: T, n: T.Distance) -> T
1228 |
1229 |
1230 | /// Return the result of advancing start by `n` positions, or until it
1231 | /// equals `end`. If `T` models `RandomAccessIndexType`, executes in
1232 | /// O(1). Otherwise, executes in O(`abs(n)`). If `T` does not model
1233 | /// `BidirectionalIndexType`, requires that `n` is non-negative.
1234 | func advance(start: T, n: T.Distance, end: T) -> T
1235 |
1236 |
1237 | /// Returns the minimum memory alignment of `T`.
1238 | func alignof(_: T.Type) -> Int
1239 |
1240 |
1241 | /// Returns the minimum memory alignment of `T`.
1242 | func alignofValue(_: T) -> Int
1243 |
1244 |
1245 | /// User code assertions.
1246 | ///
1247 | /// User code assertions and fatal errors are only enabled in debug mode. In
1248 | /// release or fast mode these checks are disabled. This means they may have no
1249 | /// effect on program semantics, depending on the assert configuration.
1250 | /// Traditional C-style assert with an optional message.
1251 | ///
1252 | /// When assertions are enabled and `condition` is false, stop program
1253 | /// execution in a debuggable state after printing a message. When
1254 | /// assertions are disabled in release and fast builds, `condition` is not even
1255 | /// evaluated.
1256 | ///
1257 | /// When assertions are turned off, the optimizer can assume that the
1258 | /// `condition` is true.
1259 | func assert(condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = default, file: StaticString = default, line: UWord = default)
1260 |
1261 |
1262 | /// Dump an object's contents using its mirror to standard output.
1263 | func dump(x: T, name: String? = default, indent: Int = default, maxDepth: Int = default, maxItems: Int = default) -> T
1264 |
1265 |
1266 | /// Dump an object's contents using its mirror to the specified output stream.
1267 | func dump(x: T, inout targetStream: TargetStream, name: String? = default, indent: Int = default, maxDepth: Int = default, maxItems: Int = default) -> T
1268 |
1269 |
1270 | /// Return a lazy `SequenceType` containing pairs (*n*, *x*), where
1271 | /// *n*\ s are consecutive `Int`\ s starting at zero, and *x*\ s are
1272 | /// the elements of `base`::
1273 | ///
1274 | /// > for (n, c) in enumerate("Swift") { println("\(n): '\(c)'" )}
1275 | /// 0: 'S'
1276 | /// 1: 'w'
1277 | /// 2: 'i'
1278 | /// 3: 'f'
1279 | /// 4: 't'
1280 | func enumerate(base: Seq) -> EnumerateSequence
1281 |
1282 |
1283 | /// Re-order the given `range` of `elements` and return a pivot index
1284 | /// *p*. Postcondition: for all *i* in `range.startIndex..<`\ *p*,
1285 | /// and *j* in *p*\ `..`__
1291 | /// over `elements`.
1292 | func partition(inout elements: C, range: Range, isOrderedBefore: (C.Generator.Element, C.Generator.Element) -> Bool) -> C.Index
1293 |
1294 |
1295 | /// Translate `input`, in the given `InputEncoding`, into `output`, in
1296 | /// the given `OutputEncoding`.
1297 | ///
1298 | /// :param: `stopOnError` causes encoding to stop when an encoding
1299 | /// error is detected in `input`, if `true`. Otherwise, U+FFFD
1300 | /// replacement characters are inserted for each detected error.
1301 | func transcode (inputEncoding: InputEncoding.Type, outputEncoding: OutputEncoding.Type, input: Input, output: Output, #stopOnError: Bool) -> (Bool)
1302 |
1303 |
1304 | /// Like `withUnsafeMutablePointer`, but passes pointers to `arg0`, `arg1`,
1305 | /// and `arg2`.
1306 | func withUnsafeMutablePointers(inout arg0: A0, inout arg1: A1, inout arg2: A2, body: (UnsafeMutablePointer, UnsafeMutablePointer, UnsafeMutablePointer) -> Result) -> Result
1307 |
1308 |
1309 | /// A collection of consecutive discrete index values.
1310 | ///
1311 | /// :param: `T` is both the element type and the index type of the
1312 | /// collection.
1313 | ///
1314 | /// Like other collections, a range containing one element has an
1315 | /// `endIndex` that is the successor of its `startIndex`; and an empty
1316 | /// range has `startIndex == endIndex`.
1317 | ///
1318 | /// Axiom: for any `Range` `r`, `r[i] == i`.
1319 | ///
1320 | /// Therefore, if `T` has a maximal value, it can serve as an
1321 | /// `endIndex`, but can never be contained in a `Range`.
1322 | ///
1323 | /// It also follows from the axiom above that `(-99..<100)[0] == 0`.
1324 | /// To prevent confusion (because some expect the result to be `-99`),
1325 | /// in a context where `T` is known to be an integer type,
1326 | /// subscripting with `T` is a compile-time error::
1327 | ///
1328 | /// // error: could not find an overload for 'subscript'...
1329 | /// println( Range(start:-99, end:100)[0] )
1330 | ///
1331 | /// However, subscripting that range still works in a generic context::
1332 | ///
1333 | /// func brackets(x: Range, i: T) -> T {
1334 | /// return x[i] // Just forward to subscript
1335 | /// }
1336 | /// println(brackets(Range(start:-99, end:100), 0)) // prints 0
1337 | struct Range : Equatable, CollectionType, Printable, DebugPrintable {
1338 |
1339 | /// Construct a copy of `x`
1340 | init(_ x: Range)
1341 |
1342 | /// Construct a range with `startIndex == start` and `endIndex ==
1343 | /// end`.
1344 | init(start: T, end: T)
1345 |
1346 | /// `true` iff the range is empty, i.e. `startIndex == endIndex`
1347 | var isEmpty: Bool { get }
1348 |
1349 | /// A type that represents a valid position in the collection.
1350 | ///
1351 | /// Valid indices consist of the position of every element and a
1352 | /// "past the end" position that's not valid for use as a subscript.
1353 | typealias Index = T
1354 | typealias Slice = Range
1355 | subscript (position: T) -> T { get }
1356 | subscript (_: T._DisabledRangeIndex) -> T { get }
1357 |
1358 | /// A type whose instances can produce the elements of this
1359 | /// sequence, in order.
1360 | typealias Generator = RangeGenerator
1361 |
1362 | /// Return a *generator* over the elements of this *sequence*.
1363 | ///
1364 | /// Complexity: O(1)
1365 | func generate() -> RangeGenerator
1366 |
1367 | /// The range's lower bound
1368 | ///
1369 | /// Identical to `endIndex` in an empty range.
1370 | var startIndex: T
1371 |
1372 | /// The range's upper bound
1373 | ///
1374 | /// `endIndex` is not a valid argument to `subscript`, and is always
1375 | /// reachable from `startIndex` by zero or more applications of
1376 | /// `successor()`.
1377 | var endIndex: T
1378 |
1379 | /// A textual representation of `self`.
1380 | var description: String { get }
1381 |
1382 | /// A textual representation of `self`, suitable for debugging.
1383 | var debugDescription: String { get }
1384 | }
1385 |
--------------------------------------------------------------------------------