GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — MessageInputBar/Example/Example/Lorem.swift at master · MessageKit/MessageInputBar Expand file tree/ Copy pathLorem.swiftMore file actions executable file ·327 lines (272 loc) · 11.8 KB / Copy pathLorem.swiftFile metadata and controlsexecutable file ·327 lines (272 loc) · 11.8 KB 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 /* MIT License Copyright (c) 2017-2018 MessageKit Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import Foundation public class Lorem { private static let wordList = [ "alias", "consequatur", "aut", "perferendis", "sit", "voluptatem", "accusantium", "doloremque", "aperiam", "eaque","ipsa", "quae", "ab", "illo", "inventore", "veritatis", "et", "quasi", "architecto", "beatae", "vitae", "dicta", "sunt", "explicabo", "aspernatur", "aut", "odit", "aut", "fugit", "sed", "quia", "consequuntur", "magni", "dolores", "eos", "qui", "ratione", "voluptatem", "sequi", "nesciunt", "neque", "dolorem", "ipsum", "quia", "dolor", "sit", "amet", "consectetur", "adipisci", "velit", "sed", "quia", "non", "numquam", "eius", "modi", "tempora", "incidunt", "ut", "labore", "et", "dolore", "magnam", "aliquam", "quaerat", "voluptatem", "ut", "enim", "ad", "minima", "veniam", "quis", "nostrum", "exercitationem", "ullam", "corporis", "nemo", "enim", "ipsam", "voluptatem", "quia", "voluptas", "sit", "suscipit", "laboriosam", "nisi", "ut", "aliquid", "ex", "ea", "commodi", "consequatur", "quis", "autem", "vel", "eum", "iure", "reprehenderit", "qui", "in", "ea", "voluptate", "velit", "esse", "quam", "nihil", "molestiae", "et", "iusto", "odio", "dignissimos", "ducimus", "qui", "blanditiis", "praesentium", "laudantium", "totam", "rem", "voluptatum", "deleniti", "atque", "corrupti", "quos", "dolores", "et", "quas", "molestias", "excepturi", "sint", "occaecati", "cupiditate", "non", "provident", "sed", "ut", "perspiciatis", "unde", "omnis", "iste", "natus", "error", "similique", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollitia", "animi", "id", "est", "laborum", "et", "dolorum", "fuga", "et", "harum", "quidem", "rerum", "facilis", "est", "et", "expedita", "distinctio", "nam", "libero", "tempore", "cum", "soluta", "nobis", "est", "eligendi", "optio", "cumque", "nihil", "impedit", "quo", "porro", "quisquam", "est", "qui", "minus", "id", "quod", "maxime", "placeat", "facere", "possimus", "omnis", "voluptas", "assumenda", "est", "omnis", "dolor", "repellendus", "temporibus", "autem", "quibusdam", "et", "aut", "consequatur", "vel", "illum", "qui", "dolorem", "eum", "fugiat", "quo", "voluptas", "nulla", "pariatur", "at", "vero", "eos", "et", "accusamus", "officiis", "debitis", "aut", "rerum", "necessitatibus", "saepe", "eveniet", "ut", "et", "voluptates", "repudiandae", "sint", "et", "molestiae", "non", "recusandae", "itaque", "earum", "rerum", "hic", "tenetur", "a", "sapiente", "delectus", "ut", "aut", "reiciendis", "voluptatibus", "maiores", "doloribus", "asperiores", "repellat" ] /** Return a random word. - returns: Returns a random word. */ public class func word() -> String { return wordList.random()! } /** Return an array of `count` words. - parameter count: The number of words to return. - returns: Returns an array of `count` words. */ public class func words(nbWords: Int = 3) -> [String] { return wordList.random(nbWords) } /** Return a string of `count` words. - parameter count: The number of words the string should contain. - returns: Returns a string of `count` words. */ public class func words(nbWords : Int = 3) -> String { return words(nbWords: nbWords).joined(separator: " ") } /** Generate a sentence of `nbWords` words. - parameter nbWords: The number of words the sentence should contain. - parameter variable: If `true`, the number of words will vary between +/- 40% of `nbWords`. - returns: */ public class func sentence(nbWords : Int = 6, variable : Bool = true) -> String { if nbWords <= 0 { return "" } let result : String = self.words(nbWords: variable ? nbWords.randomize(variation: 40) : nbWords) return result.firstCapitalized + "." } /** Generate an array of sentences. - parameter nbSentences: The number of sentences to generate. - returns: Returns an array of random sentences. */ public class func sentences(nbSentences: Int = 3) -> [String] { return (0..<nbSentences).map { _ in sentence() } } /** Generate a string of random sentences. - parameter nbSentences: The number of sentences to generate. - returns: Returns a string of random sentences. */ public class func sentences(nbSentences : Int = 3) -> String { return sentences(nbSentences: nbSentences).joined(separator: "") } /** Generate a paragraph with `nbSentences` random sentences. - parameter nbSentences: The number of sentences the paragraph should contain. - parameter variable: If `true`, the number of sentences will vary between +/- 40% of `nbSentences`. - returns: Returns a paragraph with `nbSentences` random sentences. */ public class func paragraph(nbSentences : Int = 3, variable : Bool = true) -> String { if nbSentences <= 0 { return "" } return sentences(nbSentences: variable ? nbSentences.randomize(variation: 40) : nbSentences).joined(separator: " ") } /** Generate an array of random paragraphs. - parameter nbParagraphs: The number of paragraphs to generate. - returns: Returns an array of `nbParagraphs` paragraphs. */ public class func paragraphs(nbParagraphs : Int = 3) -> [String] { return (0..<nbParagraphs).map { _ in paragraph() } } /** Generate a string of random paragrahs. - parameter nbParagraphs: The number of paragraphs to generate. - returns: Returns a string of random paragraphs. */ public class func paragraphs(nbParagraphs : Int = 3) -> String { return paragraphs(nbParagraphs: nbParagraphs).joined(separator: "\n\n") } /** Generate a string of at most `maxNbChars` characters. - parameter maxNbChars: The maximum number of characters the string should contain. - returns: Returns a string of at most `maxNbChars` characters. */ public class func text(maxNbChars : Int = 200) -> String { var result : [String] = [] if maxNbChars < 5 { return "" } else if maxNbChars < 25 { while result.count == 0 { var size = 0 while size < maxNbChars { let w = (size != 0 ? " " : "") + word() result.append(w) size += w.count } _ = result.popLast() } } else if maxNbChars < 100 { while result.count == 0 { var size = 0 while size < maxNbChars { let s = (size != 0 ? " " : "") + sentence() result.append(s) size += s.count } _ = result.popLast() } } else { while result.count == 0 { var size = 0 while size < maxNbChars { let p = (size != 0 ? "\n" : "") + paragraph() result.append(p) size += p.count } _ = result.popLast() } } return result.joined(separator: "") } } extension String { var firstCapitalized: String { var string = self string.replaceSubrange(string.startIndex...string.startIndex, with: String(string[string.startIndex]).capitalized) return string } } public extension Array { /** Shuffle the array in-place using the Fisher-Yates algorithm. */ public mutating func shuffle() { for i in 0..<(count - 1) { let j = Int(arc4random_uniform(UInt32(count - i))) + i if j != i { self.swapAt(i, j) } } } /** Return a shuffled version of the array using the Fisher-Yates algorithm. - returns: Returns a shuffled version of the array. */ public func shuffled() -> [Element] { var list = self list.shuffle() return list } /** Return a random element from the array. - returns: Returns a random element from the array or `nil` if the array is empty. */ public func random() -> Element? { return (count > 0) ? self.shuffled()[0] : nil } /** Return a random subset of `cnt` elements from the array. - returns: Returns a random subset of `cnt` elements from the array. */ public func random(_ count : Int = 1) -> [Element] { let result = shuffled() return (count > result.count) ? result : Array(result[0..<count]) } } extension Int { /** Return a random number between `min` and `max`. - note: The maximum value cannot be more than `UInt32.max - 1` - parameter min: The minimum value of the random value (defaults to `0`). - parameter max: The maximum value of the random value (defaults to `UInt32.max - 1`) - returns: Returns a random value between `min` and `max`. */ public static func random(min : Int = 0, max : Int = Int.max) -> Int { precondition(min <= max, "attempt to call random() with min > max") let diff = UInt(bitPattern: max &- min) let result = UInt.random(min: 0, max: diff) return min + Int(bitPattern: result) } public func randomize(variation : Int) -> Int { let multiplier = Double(Int.random(min: 100 - variation, max: 100 + variation)) / 100 let randomized = Double(self) * multiplier return Int(randomized) + 1 } } private extension UInt { static func random(min : UInt, max : UInt) -> UInt { precondition(min <= max, "attempt to call random() with min > max") if min == UInt.min && max == UInt.max { var result : UInt = 0 arc4random_buf(&result, MemoryLayout.size(ofValue: result)) return result } else { let range = max - min + 1 let limit = UInt.max - UInt.max % range var result : UInt = 0 repeat { arc4random_buf(&result, MemoryLayout.size(ofValue: result)) } while result >= limit result = result % range return min + result } } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |