com.linecorp.centraldogma.internal.Util.stringToLines()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中com.linecorp.centraldogma.internal.Util.stringToLines()方法的一些代码示例,展示了Util.stringToLines()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.stringToLines()方法的具体详情如下:
包路径:com.linecorp.centraldogma.internal.Util
类名称:Util
方法名:stringToLines

Util.stringToLines介绍

暂无

代码示例

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

/**
 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}.
 *
 * @param path the path of the file
 * @param oldText the old content of the file
 * @param newText the new content of the file
 */
static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText) {
  validateFilePath(path, "path");
  requireNonNull(newText, "newText");
  final List<String> oldLineList = oldText == null ? Collections.emptyList()
                           : Util.stringToLines(oldText);
  final List<String> newLineList = Util.stringToLines(newText);
  final Patch<String> patch = DiffUtils.diff(oldLineList, newLineList);
  final List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(path, path, oldLineList, patch, 3);
  return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, String.join("\n", unifiedDiff));
}

代码示例来源:origin: line/centraldogma

/**
 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}.
 *
 * @param path the path of the file
 * @param oldText the old content of the file
 * @param newText the new content of the file
 */
static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText) {
  validateFilePath(path, "path");
  requireNonNull(newText, "newText");
  final List<String> oldLineList = oldText == null ? Collections.emptyList()
                           : Util.stringToLines(oldText);
  final List<String> newLineList = Util.stringToLines(newText);
  final Patch<String> patch = DiffUtils.diff(oldLineList, newLineList);
  final List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(path, path, oldLineList, patch, 3);
  return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, String.join("\n", unifiedDiff));
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

/**
 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}.
 *
 * @param path the path of the file
 * @param oldText the old content of the file
 * @param newText the new content of the file
 */
static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText) {
  validateFilePath(path, "path");
  requireNonNull(newText, "newText");
  final List<String> oldLineList = oldText == null ? Collections.emptyList()
                           : Util.stringToLines(oldText);
  final List<String> newLineList = Util.stringToLines(newText);
  final Patch<String> patch = DiffUtils.diff(oldLineList, newLineList);
  final List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(path, path, oldLineList, patch, 3);
  return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, String.join("\n", unifiedDiff));
}

代码示例来源:origin: line/centraldogma

@Test
public void testTextPatches() throws PatchFailedException {
  final String oriStr = "1\n2\n3\n4\n5\n6\n7\n8\n9";
  final String newStr = "1a\n2\n3\n4\n5\n6\n7\n8\n9a";
  final String expectedUnifiedDiff = "--- /text_file.txt\n" +
                    "+++ /text_file.txt\n" +
                    "@@ -1,4 +1,4 @@\n" +
                    "-1\n" +
                    "+1a\n" +
                    " 2\n" +
                    " 3\n" +
                    " 4\n" +
                    "@@ -6,4 +6,4 @@\n" +
                    " 6\n" +
                    " 7\n" +
                    " 8\n" +
                    "-9\n" +
                    "+9a";
  final Change<String> change = Change.ofTextPatch("/text_file.txt", oriStr, newStr);
  assertEquals(expectedUnifiedDiff, change.content());
  final Patch<String> patch = DiffUtils.parseUnifiedDiff(Util.stringToLines(change.content()));
  final String patchedStr = String.join("\n", patch.applyTo(Util.stringToLines(oriStr)));
  assertEquals(newStr, patchedStr);
}

代码示例来源:origin: line/centraldogma

Util.stringToLines(sanitizeText((String) change.content())));
if (oldContent != null) {
  sanitizedOldText = sanitizeText(new String(oldContent, UTF_8));
  sanitizedOldTextLines = Util.stringToLines(sanitizedOldText);
} else {
  sanitizedOldText = null;

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded

Util.stringToLines(sanitizeText((String) change.content())));
if (oldContent != null) {
  sanitizedOldText = sanitizeText(new String(oldContent, UTF_8));
  sanitizedOldTextLines = Util.stringToLines(sanitizedOldText);
} else {
  sanitizedOldText = null;

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

Util.stringToLines(sanitizeText((String) change.content())));
if (oldContent != null) {
  sanitizedOldText = sanitizeText(new String(oldContent, UTF_8));
  sanitizedOldTextLines = Util.stringToLines(sanitizedOldText);
} else {
  sanitizedOldText = null;

相关文章