public static ChunkList FromNewFile(GitModule module, string text, int selectionPosition, int selectionLength, bool reset) { Chunk chunk = Chunk.FromNewFile(module, text, selectionPosition, selectionLength, reset); ChunkList result = new ChunkList(); result.Add(chunk); return(result); }
public static ChunkList FromNewFile(GitModule module, string text, int selectionPosition, int selectionLength, bool reset, byte[] FilePreabmle, Encoding fileContentEncoding) { Chunk chunk = Chunk.FromNewFile(module, text, selectionPosition, selectionLength, reset, FilePreabmle, fileContentEncoding); ChunkList result = new ChunkList(); result.Add(chunk); return(result); }
public static ChunkList GetSelectedChunks(string text, int selectionPosition, int selectionLength, out string header) { header = null; // When there is no patch, return nothing if (string.IsNullOrEmpty(text)) { return(null); } // TODO: handling submodules // Divide diff into header and patch int patchPos = text.IndexOf("@@"); if (patchPos < 1) { return(null); } header = text.Substring(0, patchPos); string diff = text.Substring(patchPos - 1); string[] chunks = diff.Split(new[] { "\n@@" }, StringSplitOptions.RemoveEmptyEntries); ChunkList selectedChunks = new ChunkList(); int i = 0; int currentPos = patchPos - 1; while (i < chunks.Length && currentPos <= selectionPosition + selectionLength) { string chunkStr = chunks[i]; currentPos += 3; // if selection intersects with chunsk if (currentPos + chunkStr.Length >= selectionPosition) { Chunk chunk = Chunk.ParseChunk(chunkStr, currentPos, selectionPosition, selectionLength); if (chunk != null) { selectedChunks.Add(chunk); } } currentPos += chunkStr.Length; i++; } return(selectedChunks); }