Mailbox
POI
Chat
Calendar
Profile
Charts
EN
Deutsch
Español
Français
MO
08:42 AM
Qui ad libero quas ipsam aliquam.
Jun 19, 2021
Cum officia voluptatum et nisi fuga impedit autem molestiae ab sit.
KS
06:42 AM
Animi maiores quas molestiae nemo quas.
Jun 18, 2021
Voluptas ut aut dignissimos aut nesciunt.
Jun 16, 2021
Distinctio ipsam ut labore rerum aut voluptatem vitae voluptatum cumque.
FA
Jun 14, 2021
Assumenda id perspiciatis alias et asperiores quia dolores quo nobis.
Show all in mailbox
Clear all
Information Page Not Found!
A new password has been sent to your e-mail address.
You do not have permission to access the API!
Your enquiry has been successfully sent.
No alerts!
Profile
Settings
Log Out
Chars
Words
Lines
Panel A
export function parsePatch(uniDiff, options = {}) { let diffstr = uniDiff.split('\n'), list = [], i = 0; function parseIndex() { let index = {}; list.push(index); // Ignore any leading junk while (i < diffstr.length) { if (/^(Index:|diff -r|@@)/.test(diffstr[i])) { break; } i++; } let header = (/^(?:Index:|diff(?: -r \w+)+) (.*)/.exec(diffstr[i])); if (header) { index.index = header[1]; i++; if (/^===/.test(diffstr[i])) { i++; } parseFileHeader(index); parseFileHeader(index); } else { // Ignore erant header components that might occur at the start of the file parseFileHeader({}); parseFileHeader({}); } index.hunks = []; while (i < diffstr.length) { if (/^(Index:|diff -r)/.test(diffstr[i])) { break; } else if (/^@@/.test(diffstr[i])) { index.hunks.push(parseHunk()); } else if (diffstr[i] && options.strict) { // Ignore unexpected content unless in strict mode throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(diffstr[i])); } else { i++; } } } // Parses the --- and +++ headers, if none are found, no lines // are consumed. function parseFileHeader(index) { let fileHeader = (/^(\-\-\-|\+\+\+)\s(\S+)\s?(.*)/.exec(diffstr[i])); if (fileHeader) { let keyPrefix = fileHeader[1] === '---' ? 'old' : 'new'; index[keyPrefix + 'FileName'] = fileHeader[2]; index[keyPrefix + 'Header'] = fileHeader[3]; i++; } } // Parses a hunk // This assumes that we are at the start of a hunk. function parseHunk() { let chunkHeaderIndex = i, chunkHeaderLine = diffstr[i++], chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/); let hunk = { oldStart: +chunkHeader[1], oldLines: +chunkHeader[2] || 1, newStart: +chunkHeader[3], newLines: +chunkHeader[4] || 1, lines: [] }; let addCount = 0, removeCount = 0; for (; i < diffstr.length; i++) { let operation = diffstr[i][0]; if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') { hunk.lines.push(diffstr[i]); if (operation === '+') { addCount++; } else if (operation === '-') { removeCount++; } else if (operation === ' ') { addCount++; removeCount++; } } else { break; } } return hunk; } while (i < diffstr.length) { parseIndex(); } return list; }
Panel B
export function parsePatch(uniDiff, options = {}) { let diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/), delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [], list = [], i = 0; function parseIndex() { let index = {}; list.push(index); // Parse diff metadata while (i < diffstr.length) { let line = diffstr[i]; // File header found, end parsing diff metadata if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) { break; } // Diff index let header = (/^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/).exec(line); if (header) { index.index = header[1]; } i++; } // Parse file headers if they are defined. Unified diff requires them, but // there's no technical issues to have an isolated hunk without file header parseFileHeader(index); parseFileHeader(index); // Parse hunks index.hunks = []; while (i < diffstr.length) { let line = diffstr[i]; if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(line)) { break; } else if (/^@@/.test(line)) { index.hunks.push(parseHunk()); } else if (line && options.strict) { // Ignore unexpected content unless in strict mode throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(line)); } else { i++; } } } // Parses the --- and +++ headers, if none are found, no lines // are consumed. function parseFileHeader(index) { const fileHeader = (/^(---|\+\+\+)\s+(.*)$/).exec(diffstr[i]); if (fileHeader) { let keyPrefix = fileHeader[1] === '---' ? 'old' : 'new'; const data = fileHeader[2].split('\t', 2); let fileName = data[0].replace(/\\\\/g, '\\'); if (/^".*"$/.test(fileName)) { fileName = fileName.substr(1, fileName.length - 2); } index[keyPrefix + 'FileName'] = fileName; index[keyPrefix + 'Header'] = (data[1] || '').trim(); i++; } } // Parses a hunk // This assumes that we are at the start of a hunk. function parseHunk() { let chunkHeaderIndex = i, chunkHeaderLine = diffstr[i++], chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/); let hunk = { oldStart: +chunkHeader[1], oldLines: +chunkHeader[2] || 1, newStart: +chunkHeader[3], newLines: +chunkHeader[4] || 1, lines: [], linedelimiters: [] }; let addCount = 0, removeCount = 0; for (; i < diffstr.length; i++) { // Lines starting with '---' could be mistaken for the "remove line" operation // But they could be the header for the next file. Therefore prune such cases out. if (diffstr[i].indexOf('--- ') === 0 && (i + 2 < diffstr.length) && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) { break; } let operation = (diffstr[i].length == 0 && i != (diffstr.length - 1)) ? ' ' : diffstr[i][0]; if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') { hunk.lines.push(diffstr[i]); hunk.linedelimiters.push(delimiters[i] || '\n'); if (operation === '+') { addCount++; } else if (operation === '-') { removeCount++; } else if (operation === ' ') { addCount++; removeCount++; } } else { break; } } return hunk; } while (i < diffstr.length) { parseIndex(); } return list; }
Result
Themes
Main Menu
Scroll to active
Accordion mode