PageSourceSearch

https://mackuba.eu/javascripts/highlighter/shBrushSwift.js

js mackuba.eu collected 2026-10-02 04:19:27 UTC 2,718 bytes, 54 lines download raw bytes

1/**
2 * Wordpress SyntaxHighlighter brush for Swift
3 * By Randex, randexdev.com
4 *
5 * Copyright (C) 2014 Randexdev
6 *
7 * 
8 * Licensed under a GNU Lesser General Public License.
9 * http://creativecommons.org/licenses/LGPL/2.1/
10 * 
11 */
12
13SyntaxHighlighter.brushes.Swift = function() {
14	
15	var datatypes =	'Character Bool Double Float Int Int8 Int16 Int32 Int64 UInt UInt8 UInt16 UInt32 UInt64 AnyObject String Void Never URL';
16	
17	var keywords = 'IBAction IBOutlet true false nil ';
18	keywords += 'super self Self copy ';
19	keywords += 'as break case class ';
20	keywords += 'continue convenience dynamic final private objc ';
21	keywords += 'default get set willSet didSet ';
22	keywords += 'else enum if is in infix internal for fallthough func import inout ';
23    keywords += 'let lazy mutable ';
24	keywords += 'naked namespace new noinline noreturn nothrow NSCopying NSManaged mutating objc override operator optional prefix protocol ';
25	keywords += 'private public required return ';
26	keywords += 'static struct switch ';
27	keywords += 'T typealias UnsafePointer var ';
28	keywords += 'unowned weak where while ';
29	keywords += 'guard defer some do try catch extension endif throws async await actor';
30
31    var funcs = 'advance enumerate find filter join min map max print println sizeof sort init'
32    
33    var operators = '= : ( ) , < > / * + - && || | & ~= >= <= == \( += -= { } '
34    
35	this.regexList = [
36        { regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },			// one line comments
37        { regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },			// multiline comments
38        { regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },			// strings
39        { regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },			// strings
40		{ regex: new RegExp(this.getKeywords(datatypes), 'gm'),     css: 'color1' },		// datatypes
41        { regex: new RegExp('\\b[A-Z]+\\w+', 'g'),                  css: 'color2' },		// capitalized names
42		{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' },		// keyword
43        { regex: new RegExp(this.getKeywords(funcs), 'gm'),         css: 'functions' },		// functions
44		{ regex: new RegExp('@\\w+\\b', 'g'),						css: 'keyword' },		// keyword
45		];
46	
47    var prefixes = ['NS', 'UI', 'SK', 'CG', 'CI', 'AV', 'CK', 'CF', 'CF', 'EK', 'GK', 'MK', 'CA'];
48    for (var i = 0; i < prefixes.length; i++) {
49        this.regexList.push({regex: new RegExp('\\b' + prefixes[i]  + '\\w+\\b', 'g'), css:'color1'})
50    }
51}
52
53SyntaxHighlighter.brushes.Swift.prototype = new SyntaxHighlighter.Highlighter();
54SyntaxHighlighter.brushes.Swift.aliases = ['swift'];

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.