public byte[] LoadBinary(string path) { var xhr = new XMLHttpRequest(); xhr.open("GET", path, false); xhr.responseType = "arraybuffer"; if (xhr.responseType != "arraybuffer") { // use VB Loader to load binary array dynamic vbArr = VbAjaxLoader("GET", path); var fileContents = vbArr.toArray(); // decode byte array to string var data = new StringBuilder(); var i = 0; while (i < (fileContents.length - 1)) { data.AppendChar((char)(fileContents[i])); i++; } var reader = GetBytesFromString(data.ToString()); return reader; } xhr.send(); if (xhr.status == 200) { var reader = NewUint8Array(xhr.response); return reader; } // Error handling if (xhr.status == 0) { throw new FileLoadException("You are offline!!\n Please Check Your Network."); } if (xhr.status == 404) { throw new FileLoadException("Requested URL not found."); } if (xhr.status == 500) { throw new FileLoadException("Internel Server Error."); } if (xhr.statusText == "parsererror") { throw new FileLoadException("Error.\nParsing JSON Request failed."); } if (xhr.statusText == "timeout") { throw new FileLoadException("Request Time out."); } throw new FileLoadException("Unknow Error: " + xhr.responseText); }
/// <summary> /// Reads a number from the stream. /// </summary> /// <returns>the read number.</returns> private int ReadNumber() { var str = new StringBuilder(); do { str.AppendChar(_ch); NextChar(); } while (IsDigit(_ch)); return Std.ParseInt(str.ToString()); }
/// <summary> /// Reads a string from the stream. /// </summary> /// <returns>the read string.</returns> private string ReadName() { var str = new StringBuilder(); do { str.AppendChar(_ch); NextChar(); } while (IsLetter(_ch) || IsDigit(_ch)); return str.ToString(); }
/// <summary> /// Reads the next terminal symbol. /// </summary> private void NewSy() { _sy = AlphaTexSymbols.No; do { if (_ch == Eof) { _sy = AlphaTexSymbols.Eof; } else if (Std.IsWhiteSpace(_ch)) { // skip whitespaces NextChar(); } else if (_ch == 0x2F /* / */) { NextChar(); if (_ch == 0x2F /* / */) { // single line comment while (_ch != 0x0D /* \r */ && _ch != 0x0A /* \n */ && _ch != Eof) { NextChar(); } } else if (_ch == 0x2A /* * */) { // multiline comment while (_ch != Eof) { if (_ch == 0x2A /* * */) // possible end { NextChar(); if (_ch == 0x2F /* / */) { NextChar(); break; } } else { NextChar(); } } } else { Error("symbol", AlphaTexSymbols.String, false); } } else if (_ch == 0x22 /* " */ || _ch == 0x27 /* ' */) { NextChar(); var s = new StringBuilder(); _sy = AlphaTexSymbols.String; while (_ch != 0x22 /* " */ && _ch != 0x27 /* ' */ && _ch != Eof) { s.AppendChar(_ch); NextChar(); } _syData = s.ToString(); NextChar(); } else if (_ch == 0x2D /* - */) // negative number { // is number? if (_allowNegatives && IsDigit(_ch)) { var number = ReadNumber(); _sy = AlphaTexSymbols.Number; _syData = number; } else { _sy = AlphaTexSymbols.String; _syData = ReadName(); } } else if (_ch == 0x2E /* . */) { _sy = AlphaTexSymbols.Dot; NextChar(); } else if (_ch == 0x3A /* : */) { _sy = AlphaTexSymbols.DoubleDot; NextChar(); } else if (_ch == 0x28 /* ( */) { _sy = AlphaTexSymbols.LParensis; NextChar(); } else if (_ch == 0x5C /* \ */) { NextChar(); var name = ReadName(); _sy = AlphaTexSymbols.MetaCommand; _syData = name; } else if (_ch == 0x29 /* ) */) { _sy = AlphaTexSymbols.RParensis; NextChar(); } else if (_ch == 0x7B /* { */) { _sy = AlphaTexSymbols.LBrace; NextChar(); } else if (_ch == 0x7D /* } */) { _sy = AlphaTexSymbols.RBrace; NextChar(); } else if (_ch == 0x7C /* | */) { _sy = AlphaTexSymbols.Pipe; NextChar(); } else if (_ch == 0x2A /* * */) { _sy = AlphaTexSymbols.Multiply; NextChar(); } else if (IsDigit(_ch)) { var number = ReadNumber(); _sy = AlphaTexSymbols.Number; _syData = number; } else if (IsLetter(_ch)) { var name = ReadName(); if (TuningParser.IsTuning(name)) { _sy = AlphaTexSymbols.Tuning; _syData = name.ToLower(); } else { _sy = AlphaTexSymbols.String; _syData = name; } } else { Error("symbol", AlphaTexSymbols.String, false); } } while (_sy == AlphaTexSymbols.No); }
public void NextToken() { var token = new StringBuilder(); int c; bool skipChar; // skip leading spaces and separators do { c = NextChar(); skipChar = Std.IsWhiteSpace(c) || c == 0x20; } while (!Eof && skipChar); // read token itself if (!Eof || !skipChar) { token.AppendChar(c); if (Std.IsCharNumber(c)) // do we have a number? { c = PeekChar(); // get first upcoming character while (!Eof && (Std.IsCharNumber(c, false) || c == 0x2E)) // while we have number characters add them { token.AppendChar(NextChar()); // peek next character for check c = PeekChar(); } } else { LastCommand = token.ToString(); } } CurrentToken = token.ToString(); }
/// <summary> /// Reads a zeroterminated ascii string from the given source /// </summary> /// <param name="data">the data source to read from</param> /// <param name="offset">the offset to start reading from</param> /// <param name="length">the max length to read</param> /// <returns>the ascii string read from the datasource.</returns> private string GetString(byte[] data, int offset, int length) { var buf = new StringBuilder(); for (int i = 0; i < length; i++) { var code = data[offset + i] & 0xFF; if (code == 0) break; // zero terminated string buf.AppendChar(code); } return buf.ToString(); }