private char[] getText(IFile file) { char[] text; if (parameters.AllFiles.getProjectRelativeName(file).equals(parameters.EditedFileName)) { text = parameters.EditedFileText; } else { using (var reader = new InputStreamReader(file.getContents(), file.getCharset())) { var sb = new StringBuilder(); int read; while ((read = reader.read(buffer)) != -1) { sb.append(buffer, 0, read); } text = new char[sb.length()]; sb.getChars(0, sizeof(text), text, 0); } } if (sizeof(text) > 0) { if (text[sizeof(text) - 1] == '\u001a') { text[sizeof(text) - 1] = ' '; } } return(text); }
/** * @param testBuf * @param cs */ private static bool asciiMapsToBasicLatin(byte[] testBuf, Charset cs) { CharsetDecoder dec = cs.newDecoder(); dec.onMalformedInput(CodingErrorAction.REPORT); dec.onUnmappableCharacter(CodingErrorAction.REPORT); Reader r = new InputStreamReader(new ByteArrayInputStream(testBuf), dec); try { for (int i = 0; i < 0x7F; i++) { if (isAsciiSupersetnessSensitive(i)) { if (r.read() != i) { return false; } } else { if (r.read() != 0x20) { return false; } } } } catch (IOException e) { return false; } catch (Exception e) { return false; } catch (CoderMalfunctionError e) { return false; } return true; }