Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: util/posix/symbolic_constants_posix.cc

Issue 700383007: Use implicit_cast<> instead of static_cast<> whenever possible (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 const char kSigPrefix[] = "SIG"; 107 const char kSigPrefix[] = "SIG";
108 108
109 } // namespace 109 } // namespace
110 110
111 namespace crashpad { 111 namespace crashpad {
112 112
113 std::string SignalToString(int signal, 113 std::string SignalToString(int signal,
114 SymbolicConstantToStringOptions options) { 114 SymbolicConstantToStringOptions options) {
115 const char* signal_name = 115 const char* signal_name =
116 static_cast<size_t>(signal) < arraysize(kSignalNames) 116 implicit_cast<size_t>(signal) < arraysize(kSignalNames)
117 ? kSignalNames[signal] 117 ? kSignalNames[signal]
118 : nullptr; 118 : nullptr;
119 if (!signal_name) { 119 if (!signal_name) {
120 if (options & kUnknownIsNumeric) { 120 if (options & kUnknownIsNumeric) {
121 return base::StringPrintf("%d", signal); 121 return base::StringPrintf("%d", signal);
122 } 122 }
123 return std::string(); 123 return std::string();
124 } 124 }
125 125
126 if (options & kUseShortName) { 126 if (options & kUseShortName) {
127 return std::string(signal_name); 127 return std::string(signal_name);
128 } 128 }
129 return base::StringPrintf("%s%s", kSigPrefix, signal_name); 129 return base::StringPrintf("%s%s", kSigPrefix, signal_name);
130 } 130 }
131 131
132 bool StringToSignal(const base::StringPiece& string, 132 bool StringToSignal(const base::StringPiece& string,
133 StringToSymbolicConstantOptions options, 133 StringToSymbolicConstantOptions options,
134 int* signal) { 134 int* signal) {
135 if ((options & kAllowFullName) || (options & kAllowShortName)) { 135 if ((options & kAllowFullName) || (options & kAllowShortName)) {
136 bool can_match_full = 136 bool can_match_full =
137 (options & kAllowFullName) && 137 (options & kAllowFullName) &&
138 string.substr(0, strlen(kSigPrefix)).compare(kSigPrefix) == 0; 138 string.substr(0, strlen(kSigPrefix)).compare(kSigPrefix) == 0;
139 base::StringPiece short_string = 139 base::StringPiece short_string =
140 can_match_full ? string.substr(strlen(kSigPrefix)) : string; 140 can_match_full ? string.substr(strlen(kSigPrefix)) : string;
141 for (int index = 0; 141 for (int index = 0;
142 index < static_cast<int>(arraysize(kSignalNames)); 142 index < implicit_cast<int>(arraysize(kSignalNames));
143 ++index) { 143 ++index) {
144 const char* signal_name = kSignalNames[index]; 144 const char* signal_name = kSignalNames[index];
145 if (!signal_name) { 145 if (!signal_name) {
146 continue; 146 continue;
147 } 147 }
148 if (can_match_full && short_string.compare(signal_name) == 0) { 148 if (can_match_full && short_string.compare(signal_name) == 0) {
149 *signal = index; 149 *signal = index;
150 return true; 150 return true;
151 } 151 }
152 if ((options & kAllowShortName) && string.compare(signal_name) == 0) { 152 if ((options & kAllowShortName) && string.compare(signal_name) == 0) {
153 *signal = index; 153 *signal = index;
154 return true; 154 return true;
155 } 155 }
156 } 156 }
157 } 157 }
158 158
159 if (options & kAllowNumber) { 159 if (options & kAllowNumber) {
160 return StringToNumber(string, signal); 160 return StringToNumber(string, signal);
161 } 161 }
162 162
163 return false; 163 return false;
164 } 164 }
165 165
166 } // namespace crashpad 166 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698