1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : ASResource.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ASResource.cpp
*
* Copyright (C) 2006-2011 by Jim Pattee <jimp03@email.com>
* Copyright (C) 1998-2002 by Tal Davidson
* <http://www.gnu.org/licenses/lgpl-3.0.html>
*
* This file is a part of Artistic Style - an indentation and
* reformatting tool for C, C++, C# and Java source files.
* <http://astyle.sourceforge.net>
*
* Artistic Style is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Artistic Style is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Artistic Style. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
#include "astyle.h"
#include <algorithm>
namespace astyle
{
const string ASResource::AS_IF = string("if");
const string ASResource::AS_ELSE = string("else");
const string ASResource::AS_FOR = string("for");
const string ASResource::AS_DO = string("do");
const string ASResource::AS_WHILE = string("while");
const string ASResource::AS_SWITCH = string("switch");
const string ASResource::AS_CASE = string("case");
const string ASResource::AS_DEFAULT = string("default");
const string ASResource::AS_CLASS = string("class");
const string ASResource::AS_VOLATILE = string("volatile");
const string ASResource::AS_STRUCT = string("struct");
const string ASResource::AS_UNION = string("union");
const string ASResource::AS_INTERFACE = string("interface");
const string ASResource::AS_NAMESPACE = string("namespace");
const string ASResource::AS_EXTERN = string("extern");
const string ASResource::AS_ENUM = string("enum");
const string ASResource::AS_PUBLIC = string("public");
const string ASResource::AS_PROTECTED = string("protected");
const string ASResource::AS_PRIVATE = string("private");
const string ASResource::AS_STATIC = string("static");
const string ASResource::AS_SYNCHRONIZED = string("synchronized");
const string ASResource::AS_OPERATOR = string("operator");
const string ASResource::AS_TEMPLATE = string("template");
const string ASResource::AS_TRY = string("try");
const string ASResource::AS_CATCH = string("catch");
const string ASResource::AS_THROW = string("throw");
const string ASResource::AS_FINALLY = string("finally");
const string ASResource::_AS_TRY = string("__try");
const string ASResource::_AS_FINALLY = string("__finally");
const string ASResource::_AS_EXCEPT = string("__except");
const string ASResource::AS_THROWS = string("throws");
const string ASResource::AS_CONST = string("const");
const string ASResource::AS_SEALED = string("sealed");
const string ASResource::AS_OVERRIDE = string("override");
const string ASResource::AS_WHERE = string("where");
const string ASResource::AS_NEW = string("new");
const string ASResource::AS_ASM = string("asm");
const string ASResource::AS__ASM__ = string("__asm__");
const string ASResource::AS_MS_ASM = string("_asm");
const string ASResource::AS_MS__ASM = string("__asm");
const string ASResource::AS_BAR_DEFINE = string("#define");
const string ASResource::AS_BAR_INCLUDE = string("#include");
const string ASResource::AS_BAR_IF = string("#if");
const string ASResource::AS_BAR_EL = string("#el");
const string ASResource::AS_BAR_ENDIF = string("#endif");
const string ASResource::AS_OPEN_BRACKET = string("{");
const string ASResource::AS_CLOSE_BRACKET = string("}");
const string ASResource::AS_OPEN_LINE_COMMENT = string("//");
const string ASResource::AS_OPEN_COMMENT = string("/*");
const string ASResource::AS_CLOSE_COMMENT = string("*/");
const string ASResource::AS_ASSIGN = string("=");
const string ASResource::AS_PLUS_ASSIGN = string("+=");
const string ASResource::AS_MINUS_ASSIGN = string("-=");
const string ASResource::AS_MULT_ASSIGN = string("*=");
const string ASResource::AS_DIV_ASSIGN = string("/=");
const string ASResource::AS_MOD_ASSIGN = string("%=");
const string ASResource::AS_OR_ASSIGN = string("|=");
const string ASResource::AS_AND_ASSIGN = string("&=");
const string ASResource::AS_XOR_ASSIGN = string("^=");
const string ASResource::AS_GR_GR_ASSIGN = string(">>=");
const string ASResource::AS_LS_LS_ASSIGN = string("<<=");
const string ASResource::AS_GR_GR_GR_ASSIGN = string(">>>=");
const string ASResource::AS_LS_LS_LS_ASSIGN = string("<<<=");
const string ASResource::AS_GCC_MIN_ASSIGN = string("<?");
const string ASResource::AS_GCC_MAX_ASSIGN = string(">?");
const string ASResource::AS_RETURN = string("return");
const string ASResource::AS_CIN = string("cin");
const string ASResource::AS_COUT = string("cout");
const string ASResource::AS_CERR = string("cerr");
const string ASResource::AS_EQUAL = string("==");
const string ASResource::AS_PLUS_PLUS = string("++");
const string ASResource::AS_MINUS_MINUS = string("--");
const string ASResource::AS_NOT_EQUAL = string("!=");
const string ASResource::AS_GR_EQUAL = string(">=");
const string ASResource::AS_GR_GR = string(">>");
const string ASResource::AS_GR_GR_GR = string(">>>");
const string ASResource::AS_LS_EQUAL = string("<=");
const string ASResource::AS_LS_LS = string("<<");
const string ASResource::AS_LS_LS_LS = string("<<<");
const string ASResource::AS_QUESTION_QUESTION = string("??");
const string ASResource::AS_EQUAL_GR = string("=>"); // C# lambda expression arrow
const string ASResource::AS_ARROW = string("->");
const string ASResource::AS_AND = string("&&");
const string ASResource::AS_OR = string("||");
const string ASResource::AS_COLON_COLON = string("::");
const string ASResource::AS_PLUS = string("+");
const string ASResource::AS_MINUS = string("-");
const string ASResource::AS_MULT = string("*");
const string ASResource::AS_DIV = string("/");
const string ASResource::AS_MOD = string("%");
const string ASResource::AS_GR = string(">");
const string ASResource::AS_LS = string("<");
const string ASResource::AS_NOT = string("!");
const string ASResource::AS_BIT_OR = string("|");
const string ASResource::AS_BIT_AND = string("&");
const string ASResource::AS_BIT_NOT = string("~");
const string ASResource::AS_BIT_XOR = string("^");
const string ASResource::AS_QUESTION = string("?");
const string ASResource::AS_COLON = string(":");
const string ASResource::AS_COMMA = string(",");
const string ASResource::AS_SEMICOLON = string(";");
const string ASResource::AS_FOREACH = string("foreach");
const string ASResource::AS_LOCK = string("lock");
const string ASResource::AS_UNSAFE = string("unsafe");
const string ASResource::AS_FIXED = string("fixed");
const string ASResource::AS_GET = string("get");
const string ASResource::AS_SET = string("set");
const string ASResource::AS_ADD = string("add");
const string ASResource::AS_REMOVE = string("remove");
const string ASResource::AS_DELEGATE = string("delegate");
const string ASResource::AS_UNCHECKED = string("unchecked");
const string ASResource::AS_CONST_CAST = string("const_cast");
const string ASResource::AS_DYNAMIC_CAST = string("dynamic_cast");
const string ASResource::AS_REINTERPRET_CAST = string("reinterpret_cast");
const string ASResource::AS_STATIC_CAST = string("static_cast");
/**
* Sort comparison function.
* Compares the length of the value of pointers in the vectors.
* The LONGEST strings will be first in the vector.
*
* @params the string pointers to be compared.
*/
bool sortOnLength(const string* a, const string* b)
{
return (*a).length() > (*b).length();
}
/**
* Sort comparison function.
* Compares the value of pointers in the vectors.
*
* @params the string pointers to be compared.
*/
bool sortOnName(const string* a, const string* b)
{
return *a < *b;
}
/**
* Build the vector of assignment operators.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param assignmentOperators a reference to the vector to be built.
*/
void ASResource::buildAssignmentOperators(vector<const string*>* assignmentOperators)
{
assignmentOperators->push_back(&AS_ASSIGN);
assignmentOperators->push_back(&AS_PLUS_ASSIGN);
assignmentOperators->push_back(&AS_MINUS_ASSIGN);
assignmentOperators->push_back(&AS_MULT_ASSIGN);
assignmentOperators->push_back(&AS_DIV_ASSIGN);
assignmentOperators->push_back(&AS_MOD_ASSIGN);
assignmentOperators->push_back(&AS_OR_ASSIGN);
assignmentOperators->push_back(&AS_AND_ASSIGN);
assignmentOperators->push_back(&AS_XOR_ASSIGN);
// Java
assignmentOperators->push_back(&AS_GR_GR_GR_ASSIGN);
assignmentOperators->push_back(&AS_GR_GR_ASSIGN);
assignmentOperators->push_back(&AS_LS_LS_ASSIGN);
// Unknown
assignmentOperators->push_back(&AS_LS_LS_LS_ASSIGN);
sort(assignmentOperators->begin(), assignmentOperators->end(), sortOnLength);
}
/**
* Build the vector of C++ cast operators.
* Used by ONLY ASFormatter.cpp
*
* @param castOperators a reference to the vector to be built.
*/
void ASResource::buildCastOperators(vector<const string*>* castOperators)
{
castOperators->push_back(&AS_CONST_CAST);
castOperators->push_back(&AS_DYNAMIC_CAST);
castOperators->push_back(&AS_REINTERPRET_CAST);
castOperators->push_back(&AS_STATIC_CAST);
}
/**
* Build the vector of header words.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param headers a reference to the vector to be built.
*/
void ASResource::buildHeaders(vector<const string*>* headers, int fileType, bool beautifier)
{
headers->push_back(&AS_IF);
headers->push_back(&AS_ELSE);
headers->push_back(&AS_FOR);
headers->push_back(&AS_WHILE);
headers->push_back(&AS_DO);
headers->push_back(&AS_SWITCH);
headers->push_back(&AS_CASE);
headers->push_back(&AS_DEFAULT);
headers->push_back(&AS_TRY);
headers->push_back(&AS_CATCH);
if (fileType == C_TYPE)
{
headers->push_back(&_AS_TRY); // __try
headers->push_back(&_AS_FINALLY); // __finally
headers->push_back(&_AS_EXCEPT); // __except
}
if (fileType == JAVA_TYPE)
{
headers->push_back(&AS_FINALLY);
headers->push_back(&AS_SYNCHRONIZED);
}
if (fileType == SHARP_TYPE)
{
headers->push_back(&AS_FINALLY);
headers->push_back(&AS_FOREACH);
headers->push_back(&AS_LOCK);
headers->push_back(&AS_FIXED);
headers->push_back(&AS_GET);
headers->push_back(&AS_SET);
headers->push_back(&AS_ADD);
headers->push_back(&AS_REMOVE);
}
if (beautifier)
{
if (fileType == C_TYPE)
{
headers->push_back(&AS_TEMPLATE);
}
if (fileType == JAVA_TYPE)
{
headers->push_back(&AS_STATIC); // for static constructor
}
}
sort(headers->begin(), headers->end(), sortOnName);
}
/**
* Build the vector of indentable headers.
* Used by ONLY ASBeautifier.cpp
*
* @param indentableHeaders a reference to the vector to be built.
*/
void ASResource::buildIndentableHeaders(vector<const string*>* indentableHeaders)
{
indentableHeaders->push_back(&AS_RETURN);
sort(indentableHeaders->begin(), indentableHeaders->end(), sortOnName);
}
/**
* Build the vector of non-assignment operators.
* Used by ONLY ASBeautifier.cpp
*
* @param nonAssignmentOperators a reference to the vector to be built.
*/
void ASResource::buildNonAssignmentOperators(vector<const string*>* nonAssignmentOperators)
{
nonAssignmentOperators->push_back(&AS_EQUAL);
nonAssignmentOperators->push_back(&AS_PLUS_PLUS);
nonAssignmentOperators->push_back(&AS_MINUS_MINUS);
nonAssignmentOperators->push_back(&AS_NOT_EQUAL);
nonAssignmentOperators->push_back(&AS_GR_EQUAL);
nonAssignmentOperators->push_back(&AS_GR_GR_GR);
nonAssignmentOperators->push_back(&AS_GR_GR);
nonAssignmentOperators->push_back(&AS_LS_EQUAL);
nonAssignmentOperators->push_back(&AS_LS_LS_LS);
nonAssignmentOperators->push_back(&AS_LS_LS);
nonAssignmentOperators->push_back(&AS_ARROW);
nonAssignmentOperators->push_back(&AS_AND);
nonAssignmentOperators->push_back(&AS_OR);
nonAssignmentOperators->push_back(&AS_EQUAL_GR);
sort(nonAssignmentOperators->begin(), nonAssignmentOperators->end(), sortOnLength);
}
/**
* Build the vector of header non-paren headers.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp.
* NOTE: Non-paren headers should also be included in the headers vector.
*
* @param nonParenHeaders a reference to the vector to be built.
*/
void ASResource::buildNonParenHeaders(vector<const string*>* nonParenHeaders, int fileType, bool beautifier)
{
nonParenHeaders->push_back(&AS_ELSE);
nonParenHeaders->push_back(&AS_DO);
nonParenHeaders->push_back(&AS_TRY);
nonParenHeaders->push_back(&AS_CATCH); // can be paren or non-paren
nonParenHeaders->push_back(&AS_CASE); // can be paren or non-paren
nonParenHeaders->push_back(&AS_DEFAULT);
if (fileType == C_TYPE)
{
nonParenHeaders->push_back(&_AS_TRY); // __try
nonParenHeaders->push_back(&_AS_FINALLY); // __finally
}
if (fileType == JAVA_TYPE)
{
nonParenHeaders->push_back(&AS_FINALLY);
}
if (fileType == SHARP_TYPE)
{
nonParenHeaders->push_back(&AS_FINALLY);
nonParenHeaders->push_back(&AS_GET);
nonParenHeaders->push_back(&AS_SET);
nonParenHeaders->push_back(&AS_ADD);
nonParenHeaders->push_back(&AS_REMOVE);
}
if (beautifier)
{
if (fileType == C_TYPE)
{
nonParenHeaders->push_back(&AS_TEMPLATE);
}
if (fileType == JAVA_TYPE)
{
nonParenHeaders->push_back(&AS_STATIC);
}
}
sort(nonParenHeaders->begin(), nonParenHeaders->end(), sortOnName);
}
/**
* Build the vector of operators.
* Used by ONLY ASFormatter.cpp
*
* @param operators a reference to the vector to be built.
*/
void ASResource::buildOperators(vector<const string*>* operators, int fileType)
{
operators->push_back(&AS_PLUS_ASSIGN);
operators->push_back(&AS_MINUS_ASSIGN);
operators->push_back(&AS_MULT_ASSIGN);
operators->push_back(&AS_DIV_ASSIGN);
operators->push_back(&AS_MOD_ASSIGN);
operators->push_back(&AS_OR_ASSIGN);
operators->push_back(&AS_AND_ASSIGN);
operators->push_back(&AS_XOR_ASSIGN);
operators->push_back(&AS_EQUAL);
operators->push_back(&AS_PLUS_PLUS);
operators->push_back(&AS_MINUS_MINUS);
operators->push_back(&AS_NOT_EQUAL);
operators->push_back(&AS_GR_EQUAL);
operators->push_back(&AS_GR_GR_GR_ASSIGN);
operators->push_back(&AS_GR_GR_ASSIGN);
operators->push_back(&AS_GR_GR_GR);
operators->push_back(&AS_GR_GR);
operators->push_back(&AS_LS_EQUAL);
operators->push_back(&AS_LS_LS_LS_ASSIGN);
operators->push_back(&AS_LS_LS_ASSIGN);
operators->push_back(&AS_LS_LS_LS);
operators->push_back(&AS_LS_LS);
operators->push_back(&AS_QUESTION_QUESTION);
operators->push_back(&AS_EQUAL_GR);
operators->push_back(&AS_ARROW);
operators->push_back(&AS_AND);
operators->push_back(&AS_OR);
operators->push_back(&AS_COLON_COLON);
operators->push_back(&AS_PLUS);
operators->push_back(&AS_MINUS);
operators->push_back(&AS_MULT);
operators->push_back(&AS_DIV);
operators->push_back(&AS_MOD);
operators->push_back(&AS_QUESTION);
operators->push_back(&AS_COLON);
operators->push_back(&AS_ASSIGN);
operators->push_back(&AS_LS);
operators->push_back(&AS_GR);
operators->push_back(&AS_NOT);
operators->push_back(&AS_BIT_OR);
operators->push_back(&AS_BIT_AND);
operators->push_back(&AS_BIT_NOT);
operators->push_back(&AS_BIT_XOR);
if (fileType == C_TYPE)
{
operators->push_back(&AS_GCC_MIN_ASSIGN);
operators->push_back(&AS_GCC_MAX_ASSIGN);
}
sort(operators->begin(), operators->end(), sortOnLength);
}
/**
* Build the vector of pre-block statements.
* Used by ONLY ASBeautifier.cpp
* NOTE: Cannot be both a header and a preBlockStatement.
*
* @param preBlockStatements a reference to the vector to be built.
*/
void ASResource::buildPreBlockStatements(vector<const string*>* preBlockStatements, int fileType)
{
preBlockStatements->push_back(&AS_CLASS);
if (fileType == C_TYPE)
{
preBlockStatements->push_back(&AS_STRUCT);
preBlockStatements->push_back(&AS_UNION);
preBlockStatements->push_back(&AS_NAMESPACE);
}
if (fileType == JAVA_TYPE)
{
preBlockStatements->push_back(&AS_INTERFACE);
preBlockStatements->push_back(&AS_THROWS);
}
if (fileType == SHARP_TYPE)
{
preBlockStatements->push_back(&AS_INTERFACE);
preBlockStatements->push_back(&AS_NAMESPACE);
preBlockStatements->push_back(&AS_WHERE);
preBlockStatements->push_back(&AS_STRUCT);
}
sort(preBlockStatements->begin(), preBlockStatements->end(), sortOnName);
}
/**
* Build the vector of pre-command headers.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp.
* NOTE: Cannot be both a header and a preCommandHeader.
*
* A preCommandHeader is in a function definition between
* the closing paren and the opening bracket.
* e.g. in "void foo() const {}", "const" is a preCommandHeader.
*/
void ASResource::buildPreCommandHeaders(vector<const string*>* preCommandHeaders, int fileType)
{
if (fileType == C_TYPE)
{
preCommandHeaders->push_back(&AS_CONST);
preCommandHeaders->push_back(&AS_VOLATILE);
preCommandHeaders->push_back(&AS_SEALED); // Visual C only
preCommandHeaders->push_back(&AS_OVERRIDE); // Visual C only
}
if (fileType == JAVA_TYPE)
{
preCommandHeaders->push_back(&AS_THROWS);
}
if (fileType == SHARP_TYPE)
{
preCommandHeaders->push_back(&AS_WHERE);
}
sort(preCommandHeaders->begin(), preCommandHeaders->end(), sortOnName);
}
/**
* Build the vector of pre-definition headers.
* Used by ONLY ASFormatter.cpp
* NOTE: Do NOT add 'enum' here. It is an array type bracket.
* NOTE: Do NOT add 'extern' here. Do not want an extra indent.
*
* @param preDefinitionHeaders a reference to the vector to be built.
*/
void ASResource::buildPreDefinitionHeaders(vector<const string*>* preDefinitionHeaders, int fileType)
{
preDefinitionHeaders->push_back(&AS_CLASS);
if (fileType == C_TYPE)
{
preDefinitionHeaders->push_back(&AS_STRUCT);
preDefinitionHeaders->push_back(&AS_UNION);
preDefinitionHeaders->push_back(&AS_NAMESPACE);
}
if (fileType == JAVA_TYPE)
{
preDefinitionHeaders->push_back(&AS_INTERFACE);
}
if (fileType == SHARP_TYPE)
{
preDefinitionHeaders->push_back(&AS_STRUCT);
preDefinitionHeaders->push_back(&AS_INTERFACE);
preDefinitionHeaders->push_back(&AS_NAMESPACE);
}
sort(preDefinitionHeaders->begin(), preDefinitionHeaders->end(), sortOnName);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ASBase Funtions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// check if a specific line position contains a keyword.
bool ASBase::findKeyword(const string &line, int i, const string &keyword) const
{
assert(isCharPotentialHeader(line, i));
// check the word
const size_t keywordLength = keyword.length();
const size_t wordEnd = i + keywordLength;
if (wordEnd > line.length())
return false;
if (line.compare(i, keywordLength, keyword) != 0)
return false;
// check that this is not part of a longer word
if (wordEnd == line.length())
return true;
if (isLegalNameChar(line[wordEnd]))
return false;
// is not a keyword if part of a definition
const char peekChar = peekNextChar(line, wordEnd - 1);
if (peekChar == ',' || peekChar == ')')
return false;
return true;
}
// get the current word on a line
// index must point to the beginning of the word
string ASBase::getCurrentWord(const string &line, size_t index) const
{
assert(isCharPotentialHeader(line, index));
size_t lineLength = line.length();
size_t i;
for (i = index; i < lineLength; i++)
{
if (!isLegalNameChar(line[i]))
break;
}
return line.substr(index, i - index);
}
} // end namespace astyle
|