diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-14 16:26:38 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-14 16:26:38 +0000 |
commit | 58fad64a169b99943c770c6b4eb9378cad1ac209 (patch) | |
tree | 6badf7c323c3475ed196dfd425d1b8a1c1ea3215 /clang-format | |
parent | d0db0f3a61aa82df5a16b93966e0034628dea491 (diff) |
Add support for Chromium style.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@172432 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-format')
-rw-r--r-- | clang-format/ClangFormat.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang-format/ClangFormat.cpp b/clang-format/ClangFormat.cpp index 507f5518..74bcc266 100644 --- a/clang-format/ClangFormat.cpp +++ b/clang-format/ClangFormat.cpp @@ -33,7 +33,8 @@ static cl::opt<int> Length( "length", cl::desc("Format a range of this length, -1 for end of file."), cl::init(-1)); static cl::opt<std::string> Style( - "style", cl::desc("Coding style, currently supports: LLVM, Google."), + "style", + cl::desc("Coding style, currently supports: LLVM, Google, Chromium."), cl::init("LLVM")); static cl::opt<bool> Inplace("i", cl::desc("Inplace edit <file>, if specified.")); @@ -53,6 +54,14 @@ static FileID createInMemoryFile(StringRef FileName, const MemoryBuffer *Source, return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User); } +static FormatStyle getStyle(StringRef name) { + if (name == "LLVM") + return getLLVMStyle(); + if (name == "Chromium") + return getChromiumStyle(); + return getGoogleStyle(); +} + static void format() { FileManager Files((FileSystemOptions())); DiagnosticsEngine Diagnostics( @@ -73,8 +82,8 @@ static void format() { End = Start.getLocWithOffset(Length); std::vector<CharSourceRange> Ranges( 1, CharSourceRange::getCharRange(Start, End)); - FormatStyle FStyle = Style == "LLVM" ? getLLVMStyle() : getGoogleStyle(); - tooling::Replacements Replaces = reformat(FStyle, Lex, Sources, Ranges); + tooling::Replacements Replaces = reformat(getStyle(Style), Lex, Sources, + Ranges); Rewriter Rewrite(Sources, LangOptions()); tooling::applyAllReplacements(Replaces, Rewrite); if (Inplace) { |