private static byte[] getFile(string s,WorkbookSettings ws) { ByteArray byteArray = new ByteArray(); int pos = 0; if (s[1] == ':') { // we have a drive letter byteArray.add(msDosDriveLetter); byteArray.add((byte)s[0]); pos = 2; } else if (s[pos] == '\\' || s[pos] == '/') { byteArray.add(sameDrive); } while (s[pos] == '\\' || s[pos] == '/') { pos++; } while (pos < s.Length) { int nextSepIndex1 = s.IndexOf('/',pos); int nextSepIndex2 = s.IndexOf('\\',pos); int nextSepIndex = 0; string nextFileNameComponent = null; if (nextSepIndex1 != -1 && nextSepIndex2 != -1) { // choose the smallest (ie. nearest) separator nextSepIndex = System.Math.Min(nextSepIndex1,nextSepIndex2); } else if (nextSepIndex1 == -1 || nextSepIndex2 == -1) { // chose the maximum separator nextSepIndex = System.Math.Max(nextSepIndex1,nextSepIndex2); } if (nextSepIndex == -1) { // no more separators nextFileNameComponent = s.Substring(pos); pos = s.Length; } else { nextFileNameComponent = s.Substring(pos,nextSepIndex); pos = nextSepIndex + 1; } if (nextFileNameComponent.Equals(".")) { // current directory - do nothing } else if (nextFileNameComponent.Equals("..")) { // parent directory byteArray.add(parentDirectory); } else { // add the filename component byteArray.add(StringHelper.getBytes(nextFileNameComponent, ws)); } if (pos < s.Length) { byteArray.add(endOfSubdirectory); } } return byteArray.getBytes(); }
private static byte[] getFile(string s, WorkbookSettings ws) { ByteArray byteArray = new ByteArray(); int pos = 0; if (s[1] == ':') { // we have a drive letter byteArray.add(msDosDriveLetter); byteArray.add((byte)s[0]); pos = 2; } else if (s[pos] == '\\' || s[pos] == '/') { byteArray.add(sameDrive); } while (s[pos] == '\\' || s[pos] == '/') { pos++; } while (pos < s.Length) { int nextSepIndex1 = s.IndexOf('/', pos); int nextSepIndex2 = s.IndexOf('\\', pos); int nextSepIndex = 0; string nextFileNameComponent = null; if (nextSepIndex1 != -1 && nextSepIndex2 != -1) { // choose the smallest (ie. nearest) separator nextSepIndex = System.Math.Min(nextSepIndex1, nextSepIndex2); } else if (nextSepIndex1 == -1 || nextSepIndex2 == -1) { // chose the maximum separator nextSepIndex = System.Math.Max(nextSepIndex1, nextSepIndex2); } if (nextSepIndex == -1) { // no more separators nextFileNameComponent = s.Substring(pos); pos = s.Length; } else { nextFileNameComponent = s.Substring(pos, nextSepIndex); pos = nextSepIndex + 1; } if (nextFileNameComponent.Equals(".")) { // current directory - do nothing } else if (nextFileNameComponent.Equals("..")) { // parent directory byteArray.add(parentDirectory); } else { // add the filename component byteArray.add(StringHelper.getBytes(nextFileNameComponent, ws)); } if (pos < s.Length) { byteArray.add(endOfSubdirectory); } } return(byteArray.getBytes()); }
private static byte[] getURL(string s,WorkbookSettings ws) { ByteArray byteArray = new ByteArray(); byteArray.add(unencodedUrl); byteArray.add((byte)s.Length); byteArray.add(StringHelper.getBytes(s,ws)); return byteArray.getBytes(); }