<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks Tony</div><div class=""><br class=""></div>Done!<div class=""><br class=""></div><div class="">Carlos</div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 04 Jan 2017, at 17:12, Tony Parker <<a href="mailto:anthony.parker@apple.com" class="">anthony.parker@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Carlos,<div class=""><br class=""></div><div class="">Thanks for proposing this. Would you mind sending it out to swift-dev or swift-evolution as well? The authors of the Swift standard library are more likely to see your message there.</div><div class=""><br class=""></div><div class="">- Tony</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2016, at 11:53 AM, Carlos García via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">I think this is important enough and useful for we to be in the core standard library</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-size: 13.6px; line-height: 1.45; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; overflow: auto; margin-top: 0px; margin-bottom: 0px; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51); orphans: 2; widows: 2;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span></span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">index</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">of</span> <span class="pl-smi" style="box-sizing: border-box;">string</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">options</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.CompareOptions <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> .<span class="pl-smi" style="box-sizing: border-box;">literal</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">?</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">of</span>: string, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">options</span>: options)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">?</span>.<span class="pl-smi" style="box-sizing: border-box;">lowerBound</span>
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">indexes</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">of</span> <span class="pl-smi" style="box-sizing: border-box;">string</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">options</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.CompareOptions <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> .<span class="pl-smi" style="box-sizing: border-box;">literal</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span>] {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> result<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span>] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> []
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> startIndex
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">while</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> range <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">of</span>: string, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">options</span>: options, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>: start<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">..<</span>endIndex) {
result.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">append</span>(range.<span class="pl-smi" style="box-sizing: border-box;">lowerBound</span>)
start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> range.<span class="pl-smi" style="box-sizing: border-box;">upperBound</span>
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> result
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">ranges</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">of</span> <span class="pl-smi" style="box-sizing: border-box;">string</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">options</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.CompareOptions <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> .<span class="pl-smi" style="box-sizing: border-box;">literal</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Range</span><<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span>>] {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> result<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Range</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> []
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> startIndex
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">while</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> range <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">of</span>: string, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">options</span>: options, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>: start<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">..<</span>endIndex) {
result.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">append</span>(range)
start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> range.<span class="pl-smi" style="box-sizing: border-box;">upperBound</span>
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> result
}
}</pre><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">Source is not mine, I’ve found here: <a href="http://stackoverflow.com/a/32306142/4550651" class="">http://stackoverflow.com/a/32306142/4550651</a></div><div class=""><br class=""></div><div class="">Best and happy 2017</div><div class=""><br class=""></div><div class="">Carlos García</div><div class=""><br class=""></div><div class=""><br class=""></div></div>_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></body></html>