Swift 3:
extension String {
func substring(fromPosition: UInt, toPosition: UInt) -> String? {
guard fromPosition <= toPosition else {
return nil
}
guard toPosition < UInt(characters.count) else {
return nil
}
let start = index(startIndex, offsetBy: String.IndexDistance(fromPosition))
let end = index(startIndex, offsetBy: String.IndexDistance(toPosition) + 1)
let range = start..<end
return substring(with: range)
}
}
"ffaabbcc".substring(fromPosition: 2, toPosition: 5) // return "aabb"
http://mxr.mozilla.org/mozilla-central/source/netwerk/base/src/nsProxyAutoConfig.js
В песочницу добавлена функция предупреждения:
80 // add predefined functions to pac
81 this._sandBox.importFunction(myIpAddress);
82 this._sandBox.importFunction(dnsResolve);
83 this._sandBox.importFunction(proxyAlert, "alert");
И отображенная функция вызывает дамп, который переходит в консоль ошибок:
108 function proxyAlert(msg) {
109 msg = XPCSafeJSObjectWrapper(msg);
110 try {
111 // It would appear that the console service is threadsafe.
112 var cns = Components.classes["@mozilla.org/consoleservice;1"]
113 .getService(Components.interfaces.nsIConsoleService);
114 cns.logStringMessage("PAC-alert: "+msg);
115 } catch (e) {
116 dump("PAC: proxyAlert ERROR: "+e+"\n");
117 }
А-ха! Предупреждающие сообщения регистрируются на консоли. Я вообще-то предпочитаю это для всплывающих окон.
Возможно, вам потребуется отключить «EnableAutoproxyResultCache» в реестре Windows. . .