-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions.swift
58 lines (52 loc) · 1.58 KB
/
Extensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Extensions.swift
// Meine UniBi
//
// Created by Saadat Baig on 14.02.20.
// Copyright © 2020 Saadat Baig. All rights reserved.
//
import Foundation
// ext
extension String{
// strip the tags and shit
func noTags(isCash: Bool) -> String {
var res = ""
if (!isCash) {
let regex = try! NSRegularExpression(pattern: "<(.*?)>(.*?)</(.*?)>")
let range = NSMakeRange(0, self.count)
res = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "")
return res
} else {
res = self.replacingOccurrences(of: #"<p class="bodytext">"#, with: "")
return String(res.prefix(4))
}
}
// reformat
func cleanUp(isCash: Bool) -> String {
let idx = self.index(self.startIndex, offsetBy: 0)
var res = self
while (true) {
if (res.isEmpty) {
break
}
if (res[idx] == " " || res[idx] == "\n") {
res.remove(at: idx)
} else {
break
}
}
if (isCash) {
return String(res.prefix(4))
} else {
return res
}
}
// replace HTML "special chars" with their unicode counterpart
func reformatHTMLChars() -> String {
var res = self
.replacingOccurrences(of: #" "#, with: "")
.replacingOccurrences(of: #"""#, with: "\"")
.replacingOccurrences(of: #"&"#, with: "&")
return res
}
}