/usr/include/glibmm-2.4/glibmm/regex.h is in libglibmm-2.4-dev 2.50.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 | // Generated by gmmproc 2.50.0 -- DO NOT MODIFY!
#ifndef _GLIBMM_REGEX_H
#define _GLIBMM_REGEX_H
/* Copyright (C) 2007 The glibmm Development Team
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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 this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmmconfig.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glibmm/error.h>
#include <glibmm/arrayhandle.h>
#include <glib.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GRegex GRegex;
#endif
namespace Glib
{
/** @addtogroup glibmmEnums glibmm Enums and Flags */
/**
* @var RegexCompileFlags REGEX_CASELESS
* Letters in the pattern match both upper- and
* lowercase letters. This option can be changed within a pattern
* by a "(?i)" option setting.
*
* @var RegexCompileFlags REGEX_MULTILINE
* By default, GRegex treats the strings as consisting
* of a single line of characters (even if it actually contains
* newlines). The "start of line" metacharacter ("^") matches only
* at the start of the string, while the "end of line" metacharacter
* ("$") matches only at the end of the string, or before a terminating
* newline (unless REGEX_DOLLAR_ENDONLY is set). When
* REGEX_MULTILINE is set, the "start of line" and "end of line"
* constructs match immediately following or immediately before any
* newline in the string, respectively, as well as at the very start
* and end. This can be changed within a pattern by a "(?m)" option
* setting.
*
* @var RegexCompileFlags REGEX_DOTALL
* A dot metacharater (".") in the pattern matches all
* characters, including newlines. Without it, newlines are excluded.
* This option can be changed within a pattern by a ("?s") option setting.
*
* @var RegexCompileFlags REGEX_EXTENDED
* Whitespace data characters in the pattern are
* totally ignored except when escaped or inside a character class.
* Whitespace does not include the VT character (code 11). In addition,
* characters between an unescaped "#" outside a character class and
* the next newline character, inclusive, are also ignored. This can
* be changed within a pattern by a "(?x)" option setting.
*
* @var RegexCompileFlags REGEX_ANCHORED
* The pattern is forced to be "anchored", that is,
* it is constrained to match only at the first matching point in the
* string that is being searched. This effect can also be achieved by
* appropriate constructs in the pattern itself such as the "^"
* metacharater.
*
* @var RegexCompileFlags REGEX_DOLLAR_ENDONLY
* A dollar metacharacter ("$") in the pattern
* matches only at the end of the string. Without this option, a
* dollar also matches immediately before the final character if
* it is a newline (but not before any other newlines). This option
* is ignored if REGEX_MULTILINE is set.
*
* @var RegexCompileFlags REGEX_UNGREEDY
* Inverts the "greediness" of the quantifiers so that
* they are not greedy by default, but become greedy if followed by "?".
* It can also be set by a "(?U)" option setting within the pattern.
*
* @var RegexCompileFlags REGEX_RAW
* Usually strings must be valid UTF-8 strings, using this
* flag they are considered as a raw sequence of bytes.
*
* @var RegexCompileFlags REGEX_NO_AUTO_CAPTURE
* Disables the use of numbered capturing
* parentheses in the pattern. Any opening parenthesis that is not
* followed by "?" behaves as if it were followed by "?:" but named
* parentheses can still be used for capturing (and they acquire numbers
* in the usual way).
*
* @var RegexCompileFlags REGEX_OPTIMIZE
* Optimize the regular expression. If the pattern will
* be used many times, then it may be worth the effort to optimize it
* to improve the speed of matches.
*
* @var RegexCompileFlags REGEX_FIRSTLINE
* Limits an unanchored pattern to match before (or at) the
* first newline. @newin{2,34}
*
* @var RegexCompileFlags REGEX_DUPNAMES
* Names used to identify capturing subpatterns need not
* be unique. This can be helpful for certain types of pattern when it
* is known that only one instance of the named subpattern can ever be
* matched.
*
* @var RegexCompileFlags REGEX_NEWLINE_CR
* Usually any newline character or character sequence is
* recognized. If this option is set, the only recognized newline character
* is '\\r'.
*
* @var RegexCompileFlags REGEX_NEWLINE_LF
* Usually any newline character or character sequence is
* recognized. If this option is set, the only recognized newline character
* is '\\n'.
*
* @var RegexCompileFlags REGEX_NEWLINE_CRLF
* Usually any newline character or character sequence is
* recognized. If this option is set, the only recognized newline character
* sequence is '\\r\\n'.
*
* @var RegexCompileFlags REGEX_NEWLINE_ANYCRLF
* Usually any newline character or character sequence
* is recognized. If this option is set, the only recognized newline character
* sequences are '\\r', '\\n', and '\\r\\n'. @newin{2,34}
*
* @var RegexCompileFlags REGEX_BSR_ANYCRLF
* Usually any newline character or character sequence
* is recognised. If this option is set, then "\\R" only recognizes the newline
* characters '\\r', '\\n' and '\\r\\n'. @newin{2,34}
*
* @var RegexCompileFlags REGEX_JAVASCRIPT_COMPAT
* Changes behaviour so that it is compatible with
* JavaScript rather than PCRE. @newin{2,34}
*
* @enum RegexCompileFlags
*
* Flags specifying compile-time options.
*
* @newin{2,14}
*
* @ingroup glibmmEnums
* @par Bitwise operators:
* <tt>%RegexCompileFlags operator|(RegexCompileFlags, RegexCompileFlags)</tt><br>
* <tt>%RegexCompileFlags operator&(RegexCompileFlags, RegexCompileFlags)</tt><br>
* <tt>%RegexCompileFlags operator^(RegexCompileFlags, RegexCompileFlags)</tt><br>
* <tt>%RegexCompileFlags operator~(RegexCompileFlags)</tt><br>
* <tt>%RegexCompileFlags& operator|=(RegexCompileFlags&, RegexCompileFlags)</tt><br>
* <tt>%RegexCompileFlags& operator&=(RegexCompileFlags&, RegexCompileFlags)</tt><br>
* <tt>%RegexCompileFlags& operator^=(RegexCompileFlags&, RegexCompileFlags)</tt><br>
*/
enum RegexCompileFlags
{
REGEX_CASELESS = 1 << 0,
REGEX_MULTILINE = 1 << 1,
REGEX_DOTALL = 1 << 2,
REGEX_EXTENDED = 1 << 3,
REGEX_ANCHORED = 1 << 4,
REGEX_DOLLAR_ENDONLY = 1 << 5,
REGEX_UNGREEDY = 1 << 9,
REGEX_RAW = 1 << 11,
REGEX_NO_AUTO_CAPTURE = 1 << 12,
REGEX_OPTIMIZE = 1 << 13,
REGEX_FIRSTLINE = 1 << 18,
REGEX_DUPNAMES = 1 << 19,
REGEX_NEWLINE_CR = 1 << 20,
REGEX_NEWLINE_LF = 1 << 21,
REGEX_NEWLINE_CRLF = 0x300000,
REGEX_NEWLINE_ANYCRLF = 1048576 | 1 << 22,
REGEX_BSR_ANYCRLF = 1 << 23,
REGEX_JAVASCRIPT_COMPAT = 1 << 25
};
/** @ingroup glibmmEnums */
inline RegexCompileFlags operator|(RegexCompileFlags lhs, RegexCompileFlags rhs)
{ return static_cast<RegexCompileFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline RegexCompileFlags operator&(RegexCompileFlags lhs, RegexCompileFlags rhs)
{ return static_cast<RegexCompileFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline RegexCompileFlags operator^(RegexCompileFlags lhs, RegexCompileFlags rhs)
{ return static_cast<RegexCompileFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline RegexCompileFlags operator~(RegexCompileFlags flags)
{ return static_cast<RegexCompileFlags>(~static_cast<unsigned>(flags)); }
/** @ingroup glibmmEnums */
inline RegexCompileFlags& operator|=(RegexCompileFlags& lhs, RegexCompileFlags rhs)
{ return (lhs = static_cast<RegexCompileFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline RegexCompileFlags& operator&=(RegexCompileFlags& lhs, RegexCompileFlags rhs)
{ return (lhs = static_cast<RegexCompileFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline RegexCompileFlags& operator^=(RegexCompileFlags& lhs, RegexCompileFlags rhs)
{ return (lhs = static_cast<RegexCompileFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
/**
* @var RegexMatchFlags REGEX_MATCH_ANCHORED
* The pattern is forced to be "anchored", that is,
* it is constrained to match only at the first matching point in the
* string that is being searched. This effect can also be achieved by
* appropriate constructs in the pattern itself such as the "^"
* metacharater.
*
* @var RegexMatchFlags REGEX_MATCH_NOTBOL
* Specifies that first character of the string is
* not the beginning of a line, so the circumflex metacharacter should
* not match before it. Setting this without REGEX_MULTILINE (at
* compile time) causes circumflex never to match. This option affects
* only the behaviour of the circumflex metacharacter, it does not
* affect "\\A".
*
* @var RegexMatchFlags REGEX_MATCH_NOTEOL
* Specifies that the end of the subject string is
* not the end of a line, so the dollar metacharacter should not match
* it nor (except in multiline mode) a newline immediately before it.
* Setting this without REGEX_MULTILINE (at compile time) causes
* dollar never to match. This option affects only the behaviour of
* the dollar metacharacter, it does not affect "\\Z" or "\\z".
*
* @var RegexMatchFlags REGEX_MATCH_NOTEMPTY
* An empty string is not considered to be a valid
* match if this option is set. If there are alternatives in the pattern,
* they are tried. If all the alternatives match the empty string, the
* entire match fails. For example, if the pattern "a?b?" is applied to
* a string not beginning with "a" or "b", it matches the empty string
* at the start of the string. With this flag set, this match is not
* valid, so GRegex searches further into the string for occurrences
* of "a" or "b".
*
* @var RegexMatchFlags REGEX_MATCH_PARTIAL
* Turns on the partial matching feature, for more
* documentation on partial matching see g_match_info_is_partial_match().
*
* @var RegexMatchFlags REGEX_MATCH_NEWLINE_CR
* Overrides the newline definition set when
* creating a new Regex, setting the '\\r' character as line terminator.
*
* @var RegexMatchFlags REGEX_MATCH_NEWLINE_LF
* Overrides the newline definition set when
* creating a new Regex, setting the '\\n' character as line terminator.
*
* @var RegexMatchFlags REGEX_MATCH_NEWLINE_CRLF
* Overrides the newline definition set when
* creating a new Regex, setting the '\\r\\n' characters sequence as line terminator.
*
* @var RegexMatchFlags REGEX_MATCH_NEWLINE_ANY
* Overrides the newline definition set when
* creating a new Regex, any Unicode newline sequence
* is recognised as a newline. These are '\\r', '\\n' and '\\rn', and the
* single characters U+000B LINE TABULATION, U+000C FORM FEED (FF),
* U+0085 NEXT LINE (NEL), U+2028 LINE SEPARATOR and
* U+2029 PARAGRAPH SEPARATOR.
*
* @var RegexMatchFlags REGEX_MATCH_NEWLINE_ANYCRLF
* Overrides the newline definition set when
* creating a new Regex; any '\\r', '\\n', or '\\r\\n' character sequence
* is recognized as a newline. @newin{2,34}
*
* @var RegexMatchFlags REGEX_MATCH_BSR_ANYCRLF
* Overrides the newline definition for "\\R" set when
* creating a new Regex; only '\\r', '\\n', or '\\r\\n' character sequences
* are recognized as a newline by "\\R". @newin{2,34}
*
* @var RegexMatchFlags REGEX_MATCH_BSR_ANY
* Overrides the newline definition for "\\R" set when
* creating a new Regex; any Unicode newline character or character sequence
* are recognized as a newline by "\\R". These are '\\r', '\\n' and '\\rn', and the
* single characters U+000B LINE TABULATION, U+000C FORM FEED (FF),
* U+0085 NEXT LINE (NEL), U+2028 LINE SEPARATOR and
* U+2029 PARAGRAPH SEPARATOR. @newin{2,34}
*
* @var RegexMatchFlags REGEX_MATCH_PARTIAL_SOFT
* An alias for REGEX_MATCH_PARTIAL. @newin{2,34}
*
* @var RegexMatchFlags REGEX_MATCH_PARTIAL_HARD
* Turns on the partial matching feature. In contrast to
* to REGEX_MATCH_PARTIAL_SOFT, this stops matching as soon as a partial match
* is found, without continuing to search for a possible complete match. See
* g_match_info_is_partial_match() for more information. @newin{2,34}
*
* @var RegexMatchFlags REGEX_MATCH_NOTEMPTY_ATSTART
* Like REGEX_MATCH_NOTEMPTY, but only applied to
* the start of the matched string. For anchored
* patterns this can only happen for pattern containing "\\K". @newin{2,34}
*
* @enum RegexMatchFlags
*
* Flags specifying match-time options.
*
* @newin{2,14}
*
* @ingroup glibmmEnums
* @par Bitwise operators:
* <tt>%RegexMatchFlags operator|(RegexMatchFlags, RegexMatchFlags)</tt><br>
* <tt>%RegexMatchFlags operator&(RegexMatchFlags, RegexMatchFlags)</tt><br>
* <tt>%RegexMatchFlags operator^(RegexMatchFlags, RegexMatchFlags)</tt><br>
* <tt>%RegexMatchFlags operator~(RegexMatchFlags)</tt><br>
* <tt>%RegexMatchFlags& operator|=(RegexMatchFlags&, RegexMatchFlags)</tt><br>
* <tt>%RegexMatchFlags& operator&=(RegexMatchFlags&, RegexMatchFlags)</tt><br>
* <tt>%RegexMatchFlags& operator^=(RegexMatchFlags&, RegexMatchFlags)</tt><br>
*/
enum RegexMatchFlags
{
REGEX_MATCH_ANCHORED = 1 << 4,
REGEX_MATCH_NOTBOL = 1 << 7,
REGEX_MATCH_NOTEOL = 1 << 8,
REGEX_MATCH_NOTEMPTY = 1 << 10,
REGEX_MATCH_PARTIAL = 1 << 15,
REGEX_MATCH_NEWLINE_CR = 1 << 20,
REGEX_MATCH_NEWLINE_LF = 1 << 21,
REGEX_MATCH_NEWLINE_CRLF = 0x300000,
REGEX_MATCH_NEWLINE_ANY = 1 << 22,
REGEX_MATCH_NEWLINE_ANYCRLF = 0x500000,
REGEX_MATCH_BSR_ANYCRLF = 1 << 23,
REGEX_MATCH_BSR_ANY = 1 << 24,
REGEX_MATCH_PARTIAL_SOFT = 0x8000,
REGEX_MATCH_PARTIAL_HARD = 1 << 27,
REGEX_MATCH_NOTEMPTY_ATSTART = 1 << 28
};
/** @ingroup glibmmEnums */
inline RegexMatchFlags operator|(RegexMatchFlags lhs, RegexMatchFlags rhs)
{ return static_cast<RegexMatchFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline RegexMatchFlags operator&(RegexMatchFlags lhs, RegexMatchFlags rhs)
{ return static_cast<RegexMatchFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline RegexMatchFlags operator^(RegexMatchFlags lhs, RegexMatchFlags rhs)
{ return static_cast<RegexMatchFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline RegexMatchFlags operator~(RegexMatchFlags flags)
{ return static_cast<RegexMatchFlags>(~static_cast<unsigned>(flags)); }
/** @ingroup glibmmEnums */
inline RegexMatchFlags& operator|=(RegexMatchFlags& lhs, RegexMatchFlags rhs)
{ return (lhs = static_cast<RegexMatchFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline RegexMatchFlags& operator&=(RegexMatchFlags& lhs, RegexMatchFlags rhs)
{ return (lhs = static_cast<RegexMatchFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline RegexMatchFlags& operator^=(RegexMatchFlags& lhs, RegexMatchFlags rhs)
{ return (lhs = static_cast<RegexMatchFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
/** %Exception class for Regex
*/
class RegexError : public Glib::Error
{
public:
/** @var Code COMPILE
* Compilation of the regular expression failed.
*
* @var Code OPTIMIZE
* Optimization of the regular expression failed.
*
* @var Code REPLACE
* Replacement failed due to an ill-formed replacement
* string.
*
* @var Code MATCH
* The match process failed.
*
* @var Code INTERNAL
* Internal error of the regular expression engine.
* @newin{2,16}
*
* @var Code STRAY_BACKSLASH
* "\\\\" at end of pattern. @newin{2,16}
*
* @var Code MISSING_CONTROL_CHAR
* "\\\\c" at end of pattern. @newin{2,16}
*
* @var Code UNRECOGNIZED_ESCAPE
* Unrecognized character follows "\\\\".
* @newin{2,16}
*
* @var Code QUANTIFIERS_OUT_OF_ORDER
* Numbers out of order in "{}"
* quantifier. @newin{2,16}
*
* @var Code QUANTIFIER_TOO_BIG
* Number too big in "{}" quantifier.
* @newin{2,16}
*
* @var Code UNTERMINATED_CHARACTER_CLASS
* Missing terminating "]" for
* character class. @newin{2,16}
*
* @var Code INVALID_ESCAPE_IN_CHARACTER_CLASS
* Invalid escape sequence
* in character class. @newin{2,16}
*
* @var Code RANGE_OUT_OF_ORDER
* Range out of order in character class.
* @newin{2,16}
*
* @var Code NOTHING_TO_REPEAT
* Nothing to repeat. @newin{2,16}
*
* @var Code UNRECOGNIZED_CHARACTER
* Unrecognized character after "(?",
* "(?<" or "(?P". @newin{2,16}
*
* @var Code POSIX_NAMED_CLASS_OUTSIDE_CLASS
* POSIX named classes are
* supported only within a class. @newin{2,16}
*
* @var Code UNMATCHED_PARENTHESIS
* Missing terminating ")" or ")"
* without opening "(". @newin{2,16}
*
* @var Code INEXISTENT_SUBPATTERN_REFERENCE
* Reference to non-existent
* subpattern. @newin{2,16}
*
* @var Code UNTERMINATED_COMMENT
* Missing terminating ")" after comment.
* @newin{2,16}
*
* @var Code EXPRESSION_TOO_LARGE
* Regular expression too large.
* @newin{2,16}
*
* @var Code MEMORY_ERROR
* Failed to get memory. @newin{2,16}
*
* @var Code VARIABLE_LENGTH_LOOKBEHIND
* Lookbehind assertion is not
* fixed length. @newin{2,16}
*
* @var Code MALFORMED_CONDITION
* Malformed number or name after "(?(".
* @newin{2,16}
*
* @var Code TOO_MANY_CONDITIONAL_BRANCHES
* Conditional group contains
* more than two branches. @newin{2,16}
*
* @var Code ASSERTION_EXPECTED
* Assertion expected after "(?(".
* @newin{2,16}
*
* @var Code UNKNOWN_POSIX_CLASS_NAME
* Unknown POSIX class name.
* @newin{2,16}
*
* @var Code POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED
* POSIX collating
* elements are not supported. @newin{2,16}
*
* @var Code HEX_CODE_TOO_LARGE
* Character value in "\\\\x{...}" sequence
* is too large. @newin{2,16}
*
* @var Code INVALID_CONDITION
* Invalid condition "(?(0)". @newin{2,16}
*
* @var Code SINGLE_BYTE_MATCH_IN_LOOKBEHIND
* \\\\C not allowed in
* lookbehind assertion. @newin{2,16}
*
* @var Code INFINITE_LOOP
* Recursive call could loop indefinitely.
* @newin{2,16}
*
* @var Code MISSING_SUBPATTERN_NAME_TERMINATOR
* Missing terminator
* in subpattern name. @newin{2,16}
*
* @var Code DUPLICATE_SUBPATTERN_NAME
* Two named subpatterns have
* the same name. @newin{2,16}
*
* @var Code MALFORMED_PROPERTY
* Malformed "\\\\P" or "\\\\p" sequence.
* @newin{2,16}
*
* @var Code UNKNOWN_PROPERTY
* Unknown property name after "\\\\P" or
* "\\\\p". @newin{2,16}
*
* @var Code SUBPATTERN_NAME_TOO_LONG
* Subpattern name is too long
* (maximum 32 characters). @newin{2,16}
*
* @var Code TOO_MANY_SUBPATTERNS
* Too many named subpatterns (maximum
* 10,000). @newin{2,16}
*
* @var Code INVALID_OCTAL_VALUE
* Octal value is greater than "\\\\377".
* @newin{2,16}
*
* @var Code TOO_MANY_BRANCHES_IN_DEFINE
* "DEFINE" group contains more
* than one branch. @newin{2,16}
*
* @var Code DEFINE_REPETION
* Repeating a "DEFINE" group is not allowed.
* This error is never raised. @newin{2,16} Deprecated: 2.34.
*
* @var Code INCONSISTENT_NEWLINE_OPTIONS
* Inconsistent newline options.
* @newin{2,16}
*
* @var Code MISSING_BACK_REFERENCE
* "\\\\g" is not followed by a braced,
* angle-bracketed, or quoted name or number, or by a plain number. @newin{2,16}
*
* @var Code INVALID_RELATIVE_REFERENCE
* Relative reference must not be zero. @newin{2,34}
*
* @var Code BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN
* The backtracing
* control verb used does not allow an argument. @newin{2,34}
*
* @var Code UNKNOWN_BACKTRACKING_CONTROL_VERB
* Unknown backtracing
* control verb. @newin{2,34}
*
* @var Code NUMBER_TOO_BIG
* Number is too big in escape sequence. @newin{2,34}
*
* @var Code MISSING_SUBPATTERN_NAME
* Missing subpattern name. @newin{2,34}
*
* @var Code MISSING_DIGIT
* Missing digit. @newin{2,34}
*
* @var Code INVALID_DATA_CHARACTER
* In JavaScript compatibility mode,
* "[" is an invalid data character. @newin{2,34}
*
* @var Code EXTRA_SUBPATTERN_NAME
* Different names for subpatterns of the
* same number are not allowed. @newin{2,34}
*
* @var Code BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED
* The backtracing control
* verb requires an argument. @newin{2,34}
*
* @var Code INVALID_CONTROL_CHAR
* "\\\\c" must be followed by an ASCII
* character. @newin{2,34}
*
* @var Code MISSING_NAME
* "\\\\k" is not followed by a braced, angle-bracketed, or
* quoted name. @newin{2,34}
*
* @var Code NOT_SUPPORTED_IN_CLASS
* "\\\\N" is not supported in a class. @newin{2,34}
*
* @var Code TOO_MANY_FORWARD_REFERENCES
* Too many forward references. @newin{2,34}
*
* @var Code NAME_TOO_LONG
* The name is too long in "(*MARK)", "(*PRUNE)",
* "(*SKIP)", or "(*THEN)". @newin{2,34}
*
* @var Code CHARACTER_VALUE_TOO_LARGE
* The character value in the \\\\u sequence is
* too large. @newin{2,34}
*
* @enum Code
*
* %Error codes returned by regular expressions functions.
*
* @newin{2,14}
*/
enum Code
{
COMPILE = 0,
OPTIMIZE = 1,
REPLACE = 2,
MATCH = 3,
INTERNAL = 4,
STRAY_BACKSLASH = 101,
MISSING_CONTROL_CHAR = 102,
UNRECOGNIZED_ESCAPE = 103,
QUANTIFIERS_OUT_OF_ORDER = 104,
QUANTIFIER_TOO_BIG = 105,
UNTERMINATED_CHARACTER_CLASS = 106,
INVALID_ESCAPE_IN_CHARACTER_CLASS = 107,
RANGE_OUT_OF_ORDER = 108,
NOTHING_TO_REPEAT = 109,
UNRECOGNIZED_CHARACTER = 112,
POSIX_NAMED_CLASS_OUTSIDE_CLASS = 113,
UNMATCHED_PARENTHESIS = 114,
INEXISTENT_SUBPATTERN_REFERENCE = 115,
UNTERMINATED_COMMENT = 118,
EXPRESSION_TOO_LARGE = 120,
MEMORY_ERROR = 121,
VARIABLE_LENGTH_LOOKBEHIND = 125,
MALFORMED_CONDITION = 126,
TOO_MANY_CONDITIONAL_BRANCHES = 127,
ASSERTION_EXPECTED = 128,
UNKNOWN_POSIX_CLASS_NAME = 130,
POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED = 131,
HEX_CODE_TOO_LARGE = 134,
INVALID_CONDITION = 135,
SINGLE_BYTE_MATCH_IN_LOOKBEHIND = 136,
INFINITE_LOOP = 140,
MISSING_SUBPATTERN_NAME_TERMINATOR = 142,
DUPLICATE_SUBPATTERN_NAME = 143,
MALFORMED_PROPERTY = 146,
UNKNOWN_PROPERTY = 147,
SUBPATTERN_NAME_TOO_LONG = 148,
TOO_MANY_SUBPATTERNS = 149,
INVALID_OCTAL_VALUE = 151,
TOO_MANY_BRANCHES_IN_DEFINE = 154,
DEFINE_REPETION = 155,
INCONSISTENT_NEWLINE_OPTIONS = 156,
MISSING_BACK_REFERENCE = 157,
INVALID_RELATIVE_REFERENCE = 158,
BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN = 159,
UNKNOWN_BACKTRACKING_CONTROL_VERB = 160,
NUMBER_TOO_BIG = 161,
MISSING_SUBPATTERN_NAME = 162,
MISSING_DIGIT = 163,
INVALID_DATA_CHARACTER = 164,
EXTRA_SUBPATTERN_NAME = 165,
BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED = 166,
INVALID_CONTROL_CHAR = 168,
MISSING_NAME = 169,
NOT_SUPPORTED_IN_CLASS = 171,
TOO_MANY_FORWARD_REFERENCES = 172,
NAME_TOO_LONG = 175,
CHARACTER_VALUE_TOO_LARGE = 176
};
RegexError(Code error_code, const Glib::ustring& error_message);
explicit RegexError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif //DOXYGEN_SHOULD_SKIP_THIS
};
class MatchInfo;
/** Perl-compatible regular expressions - matches strings against regular expressions.
*
* The Glib::Regex functions implement regular expression pattern matching using
* syntax and semantics similar to Perl regular expression.
*
* Some functions accept a start_position argument, setting it differs from just
* passing over a shortened string and setting REGEX_MATCH_NOTBOL in the case
* of a pattern that begins with any kind of lookbehind assertion. For example,
* consider the pattern "\Biss\B" which finds occurrences of "iss" in the middle
* of words. ("\B" matches only if the current position in the subject is not a
* word boundary.) When applied to the string "Mississipi" from the fourth byte,
* namely "issipi", it does not match, because "\B" is always false at the
* start of the subject, which is deemed to be a word boundary. However, if
* the entire string is passed , but with start_position set to 4, it finds the
* second occurrence of "iss" because it is able to look behind the starting point
* to discover that it is preceded by a letter.
*
* Note that, unless you set the REGEX_RAW flag, all the strings passed to these
* functions must be encoded in UTF-8. The lengths and the positions inside the
* strings are in bytes and not in characters, so, for instance,
* "\xc3\xa0" (i.e. "Ã ") is two bytes long but it is treated as a single
* character. If you set REGEX_RAW the strings can be non-valid UTF-8 strings
* and a byte is treated as a character, so "\xc3\xa0" is two bytes and
* two characters long.
*
* When matching a pattern, "\n" matches only against a "\n" character in the
* string, and "\r" matches only a "\r" character. To match any newline sequence
* use "\R". This particular group matches either the two-character sequence
* CR + LF ("\r\n"), or one of the single characters LF (linefeed, U+000A, "\n"),
* VT (vertical tab, U+000B, "\v"), FF (formfeed, U+000C, "\f"), CR (carriage
* return, U+000D, "\r"), NEL (next line, U+0085), LS (line separator, U+2028),
* or PS (paragraph separator, U+2029).
*
* The behaviour of the dot, circumflex, and dollar metacharacters are affected
* by newline characters, the default is to recognize any newline character (the
* same characters recognized by "\R"). This can be changed with REGEX_NEWLINE_CR,
* REGEX_NEWLINE_LF and REGEX_NEWLINE_CRLF compile options, and with
* REGEX_MATCH_NEWLINE_ANY, REGEX_MATCH_NEWLINE_CR, REGEX_MATCH_NEWLINE_LF
* and REGEX_MATCH_NEWLINE_CRLF match options. These settings are also
* relevant when compiling a pattern if REGEX_EXTENDED is set, and an unescaped
* "#" outside a character class is encountered. This indicates a comment that
* lasts until after the next newline.
*
* Creating and manipulating the same Glib::Regex class from different threads is
* not a problem as Glib::Regex does not modify its internal state between creation and
* destruction, on the other hand Glib::MatchInfo is not threadsafe.
*
* The regular expressions low level functionalities are obtained through the
* excellent PCRE library written by Philip Hazel.
*
* @newin{2,14}
*/
class Regex final
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
using CppObjectType = Regex;
using BaseObjectType = GRegex;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/** Increment the reference count for this object.
* You should never need to do this manually - use the object via a RefPtr instead.
*/
void reference() const;
/** Decrement the reference count for this object.
* You should never need to do this manually - use the object via a RefPtr instead.
*/
void unreference() const;
///Provides access to the underlying C instance.
GRegex* gobj();
///Provides access to the underlying C instance.
const GRegex* gobj() const;
///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
GRegex* gobj_copy() const;
Regex() = delete;
// noncopyable
Regex(const Regex&) = delete;
Regex& operator=(const Regex&) = delete;
protected:
// Do not derive this. Glib::Regex can neither be constructed nor deleted.
void operator delete(void*, std::size_t);
private:
public:
static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
/** Gets the pattern string associated with @a regex, i.e.\ a copy of
* the string passed to g_regex_new().
*
* @newin{2,14}
*
* @return The pattern of @a regex.
*/
Glib::ustring get_pattern() const;
/** Returns the number of the highest back reference
* in the pattern, or 0 if the pattern does not contain
* back references.
*
* @newin{2,14}
*
* @return The number of the highest back reference.
*/
int get_max_backref() const;
/** Returns the number of capturing subpatterns in the pattern.
*
* @newin{2,14}
*
* @return The number of capturing subpatterns.
*/
int get_capture_count() const;
/** Checks whether the pattern contains explicit CR or LF references.
*
* @newin{2,34}
*
* @return <tt>true</tt> if the pattern contains explicit CR or LF references.
*/
bool get_has_cr_or_lf() const;
/** Gets the number of characters in the longest lookbehind assertion in the
* pattern. This information is useful when doing multi-segment matching using
* the partial matching facilities.
*
* @newin{2,38}
*
* @return The number of characters in the longest lookbehind assertion.
*/
int get_max_lookbehind() const;
/** Retrieves the number of the subexpression named @a name.
*
* @newin{2,14}
*
* @param name Name of the subexpression.
* @return The number of the subexpression or -1 if @a name
* does not exists.
*/
int get_string_number(const Glib::ustring& name) const;
/** Returns the compile options that @a regex was created with.
*
* Depending on the version of PCRE that is used, this may or may not
* include flags set by option expressions such as `(?i)` found at the
* top-level within the compiled pattern.
*
* @newin{2,26}
*
* @return Flags from RegexCompileFlags.
*/
RegexCompileFlags get_compile_flags() const;
/** Returns the match options that @a regex was created with.
*
* @newin{2,26}
*
* @return Flags from RegexMatchFlags.
*/
RegexMatchFlags get_match_flags() const;
static Glib::ustring escape_string(const Glib::ustring& string);
/** Scans for a match in @a string for @a pattern.
*
* This function is equivalent to g_regex_match() but it does not
* require to compile the pattern with g_regex_new(), avoiding some
* lines of code when you need just to do a match without extracting
* substrings, capture counts, and so on.
*
* If this function is to be called on the same @a pattern more than
* once, it's more efficient to compile the pattern once with
* g_regex_new() and then use g_regex_match().
*
* @newin{2,14}
*
* @param pattern The regular expression.
* @param string The string to scan for matches.
* @param compile_options Compile options for the regular expression, or 0.
* @param match_options Match options, or 0.
* @return <tt>true</tt> if the string matched, <tt>false</tt> otherwise.
*/
static bool match_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
/** Scans for a match in string for the pattern in @a regex.
* The @a match_options are combined with the match options specified
* when the @a regex structure was created, letting you have more
* flexibility in reusing Regex structures.
*
* A MatchInfo structure, used to get information on the match,
* is stored in @a match_info if not <tt>nullptr</tt>. Note that if @a match_info
* is not <tt>nullptr</tt> then it is created even if the function returns <tt>false</tt>,
* i.e. you must free it regardless if regular expression actually matched.
*
* To retrieve all the non-overlapping matches of the pattern in
* string you can use g_match_info_next().
*
*
* [C example ellipted]
*
* @a string is not copied and is used in MatchInfo internally. If
* you use any MatchInfo method (except g_match_info_free()) after
* freeing or modifying @a string then the behaviour is undefined.
*
* @newin{2,14}
*
* @param string The string to scan for matches.
* @param match_options Match options.
* @param match_info Pointer to location where to store
* the MatchInfo, or <tt>nullptr</tt> if you do not need it.
* @return <tt>true</tt> is the string matched, <tt>false</tt> otherwise.
*/
bool match(
const Glib::ustring& string,
Glib::MatchInfo& match_info,
RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)
);
/// A match() method not requiring a Glib::MatchInfo.
bool match(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
/// A match() method with a start position and a Glib::MatchInfo.
bool match(
const Glib::ustring& string,
int start_position,
Glib::MatchInfo& match_info,
RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)
);
/** Scans for a match in string for the pattern in @a regex.
* The @a match_options are combined with the match options specified
* when the @a regex structure was created, letting you have more
* flexibility in reusing Regex structures.
*
* Setting @a start_position differs from just passing over a shortened
* string and setting REGEX_MATCH_NOTBOL in the case of a pattern
* that begins with any kind of lookbehind assertion, such as "\\b".
*
* A MatchInfo structure, used to get information on the match, is
* stored in @a match_info if not <tt>nullptr</tt>. Note that if @a match_info is
* not <tt>nullptr</tt> then it is created even if the function returns <tt>false</tt>,
* i.e. you must free it regardless if regular expression actually
* matched.
*
* @a string is not copied and is used in MatchInfo internally. If
* you use any MatchInfo method (except g_match_info_free()) after
* freeing or modifying @a string then the behaviour is undefined.
*
* To retrieve all the non-overlapping matches of the pattern in
* string you can use g_match_info_next().
*
*
* [C example ellipted]
*
* @newin{2,14}
*
* @param string The string to scan for matches.
* @param string_len The length of @a string, or -1 if @a string is nul-terminated.
* @param start_position Starting index of the string to match, in bytes.
* @param match_options Match options.
* @param match_info Pointer to location where to store
* the MatchInfo, or <tt>nullptr</tt> if you do not need it.
* @return <tt>true</tt> is the string matched, <tt>false</tt> otherwise.
*/
bool match(
const Glib::ustring& string,
gssize string_len,
int start_position,
Glib::MatchInfo& match_info,
RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)
);
/// A match() method with a start position not requiring a Glib::MatchInfo.
bool match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
/** A match() method with a string length and start position not requiring a
* Glib::MatchInfo.
*/
bool match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
/** Using the standard algorithm for regular expression matching only
* the longest match in the string is retrieved. This function uses
* a different algorithm so it can retrieve all the possible matches.
* For more documentation see g_regex_match_all_full().
*
* A MatchInfo structure, used to get information on the match, is
* stored in @a match_info if not <tt>nullptr</tt>. Note that if @a match_info is
* not <tt>nullptr</tt> then it is created even if the function returns <tt>false</tt>,
* i.e. you must free it regardless if regular expression actually
* matched.
*
* @a string is not copied and is used in MatchInfo internally. If
* you use any MatchInfo method (except g_match_info_free()) after
* freeing or modifying @a string then the behaviour is undefined.
*
* @newin{2,14}
*
* @param string The string to scan for matches.
* @param match_options Match options.
* @param match_info Pointer to location where to store
* the MatchInfo, or <tt>nullptr</tt> if you do not need it.
* @return <tt>true</tt> is the string matched, <tt>false</tt> otherwise.
*/
bool match_all(
const Glib::ustring& string,
Glib::MatchInfo& match_info,
RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)
);
/// A match_all() method not requiring a Glib::MatchInfo.
bool match_all(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
/// A match_all() method with a start positon and a Glib::MatchInfo.
bool match_all(
const Glib::ustring& string,
int start_position,
Glib::MatchInfo& match_info,
RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)
);
/** Using the standard algorithm for regular expression matching only
* the longest match in the string is retrieved, it is not possible
* to obtain all the available matches. For instance matching
* "<a> <b> <c>" against the pattern "<.*>"
* you get "<a> <b> <c>".
*
* This function uses a different algorithm (called DFA, i.e. deterministic
* finite automaton), so it can retrieve all the possible matches, all
* starting at the same point in the string. For instance matching
* "<a> <b> <c>" against the pattern "<.*>;"
* you would obtain three matches: "<a> <b> <c>",
* "<a> <b>" and "<a>".
*
* The number of matched strings is retrieved using
* g_match_info_get_match_count(). To obtain the matched strings and
* their position you can use, respectively, g_match_info_fetch() and
* g_match_info_fetch_pos(). Note that the strings are returned in
* reverse order of length; that is, the longest matching string is
* given first.
*
* Note that the DFA algorithm is slower than the standard one and it
* is not able to capture substrings, so backreferences do not work.
*
* Setting @a start_position differs from just passing over a shortened
* string and setting REGEX_MATCH_NOTBOL in the case of a pattern
* that begins with any kind of lookbehind assertion, such as "\\b".
*
* A MatchInfo structure, used to get information on the match, is
* stored in @a match_info if not <tt>nullptr</tt>. Note that if @a match_info is
* not <tt>nullptr</tt> then it is created even if the function returns <tt>false</tt>,
* i.e. you must free it regardless if regular expression actually
* matched.
*
* @a string is not copied and is used in MatchInfo internally. If
* you use any MatchInfo method (except g_match_info_free()) after
* freeing or modifying @a string then the behaviour is undefined.
*
* @newin{2,14}
*
* @param string The string to scan for matches.
* @param string_len The length of @a string, or -1 if @a string is nul-terminated.
* @param start_position Starting index of the string to match, in bytes.
* @param match_options Match options.
* @param match_info Pointer to location where to store
* the MatchInfo, or <tt>nullptr</tt> if you do not need it.
* @return <tt>true</tt> is the string matched, <tt>false</tt> otherwise.
*/
/// @throw Glib::Error.
bool match_all(
const Glib::ustring& string,
gssize string_len,
int start_position,
Glib::MatchInfo& match_info,
RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)
);
/** A match_all() method with a start position not requiring a
* Glib::MatchInfo.
*/
bool match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
/** A match_all() method with a start position and a string length not
* requiring a Glib::MatchInfo.
*/
bool match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
/** Breaks the string on the pattern, and returns an array of
* the tokens. If the pattern contains capturing parentheses,
* then the text for each of the substrings will also be returned.
* If the pattern does not match anywhere in the string, then the
* whole string is returned as the first token.
*
* This function is equivalent to g_regex_split() but it does
* not require to compile the pattern with g_regex_new(), avoiding
* some lines of code when you need just to do a split without
* extracting substrings, capture counts, and so on.
*
* If this function is to be called on the same @a pattern more than
* once, it's more efficient to compile the pattern once with
* g_regex_new() and then use g_regex_split().
*
* As a special case, the result of splitting the empty string ""
* is an empty vector, not a vector containing a single string.
* The reason for this special case is that being able to represent
* a empty vector is typically more useful than consistent handling
* of empty elements. If you do need to represent empty elements,
* you'll need to check for the empty string before calling this
* function.
*
* A pattern that can match empty strings splits @a string into
* separate characters wherever it matches the empty string between
* characters. For example splitting "ab c" using as a separator
* "\\s*", you will get "a", "b" and "c".
*
* @newin{2,14}
*
* @param pattern The regular expression.
* @param string The string to scan for matches.
* @param compile_options Compile options for the regular expression, or 0.
* @param match_options Match options, or 0.
* @return A <tt>nullptr</tt>-terminated array of strings.
*/
static Glib::StringArrayHandle split_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
/** Breaks the string on the pattern, and returns an array of the tokens.
* If the pattern contains capturing parentheses, then the text for each
* of the substrings will also be returned. If the pattern does not match
* anywhere in the string, then the whole string is returned as the first
* token.
*
* As a special case, the result of splitting the empty string "" is an
* empty vector, not a vector containing a single string. The reason for
* this special case is that being able to represent a empty vector is
* typically more useful than consistent handling of empty elements. If
* you do need to represent empty elements, you'll need to check for the
* empty string before calling this function.
*
* A pattern that can match empty strings splits @a string into separate
* characters wherever it matches the empty string between characters.
* For example splitting "ab c" using as a separator "\\s*", you will get
* "a", "b" and "c".
*
* @newin{2,14}
*
* @param string The string to split with the pattern.
* @param match_options Match time option flags.
* @return A <tt>nullptr</tt>-terminated gchar ** array.
*/
Glib::StringArrayHandle split(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
/** Breaks the string on the pattern, and returns an array of the tokens.
* If the pattern contains capturing parentheses, then the text for each
* of the substrings will also be returned. If the pattern does not match
* anywhere in the string, then the whole string is returned as the first
* token.
*
* As a special case, the result of splitting the empty string "" is an
* empty vector, not a vector containing a single string. The reason for
* this special case is that being able to represent a empty vector is
* typically more useful than consistent handling of empty elements. If
* you do need to represent empty elements, you'll need to check for the
* empty string before calling this function.
*
* A pattern that can match empty strings splits @a string into separate
* characters wherever it matches the empty string between characters.
* For example splitting "ab c" using as a separator "\\s*", you will get
* "a", "b" and "c".
*
* Setting @a start_position differs from just passing over a shortened
* string and setting REGEX_MATCH_NOTBOL in the case of a pattern
* that begins with any kind of lookbehind assertion, such as "\\b".
*
* @newin{2,14}
*
* @param string The string to split with the pattern.
* @param string_len The length of @a string, or -1 if @a string is nul-terminated.
* @param start_position Starting index of the string to match, in bytes.
* @param match_options Match time option flags.
* @param max_tokens The maximum number of tokens to split @a string into.
* If this is less than 1, the string is split completely.
* @return A <tt>nullptr</tt>-terminated gchar ** array.
*/
Glib::StringArrayHandle split(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0), int max_tokens = 0) const;
Glib::StringArrayHandle split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const;
/** Replaces all occurrences of the pattern in @a regex with the
* replacement text. Backreferences of the form '\\number' or
* '\\g<number>' in the replacement text are interpolated by the
* number-th captured subexpression of the match, '\\g<name>' refers
* to the captured subexpression with the given name. '\\0' refers
* to the complete match, but '\\0' followed by a number is the octal
* representation of a character. To include a literal '\\' in the
* replacement, write '\\\\'.
*
* There are also escapes that changes the case of the following text:
*
* - \\l: Convert to lower case the next character
* - \\u: Convert to upper case the next character
* - \\L: Convert to lower case till \\E
* - \\U: Convert to upper case till \\E
* - \\E: End case modification
*
* If you do not need to use backreferences use g_regex_replace_literal().
*
* The @a replacement string must be UTF-8 encoded even if REGEX_RAW was
* passed to g_regex_new(). If you want to use not UTF-8 encoded stings
* you can use g_regex_replace_literal().
*
* Setting @a start_position differs from just passing over a shortened
* string and setting REGEX_MATCH_NOTBOL in the case of a pattern that
* begins with any kind of lookbehind assertion, such as "\\b".
*
* @newin{2,14}
*
* @param string The string to perform matches against.
* @param string_len The length of @a string, or -1 if @a string is nul-terminated.
* @param start_position Starting index of the string to match, in bytes.
* @param replacement Text to replace each match with.
* @param match_options Options for the match.
* @return A newly allocated string containing the replacements.
*/
Glib::ustring replace(const gchar* string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
Glib::ustring replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options);
/** Replaces all occurrences of the pattern in @a regex with the
* replacement text. @a replacement is replaced literally, to
* include backreferences use g_regex_replace().
*
* Setting @a start_position differs from just passing over a
* shortened string and setting REGEX_MATCH_NOTBOL in the
* case of a pattern that begins with any kind of lookbehind
* assertion, such as "\\b".
*
* @newin{2,14}
*
* @param string The string to perform matches against.
* @param string_len The length of @a string, or -1 if @a string is nul-terminated.
* @param start_position Starting index of the string to match, in bytes.
* @param replacement Text to replace each match with.
* @param match_options Options for the match.
* @return A newly allocated string containing the replacements.
*/
Glib::ustring replace_literal(const gchar * string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
Glib::ustring replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options);
/** Replaces occurrences of the pattern in regex with the output of
* @a eval for that occurrence.
*
* Setting @a start_position differs from just passing over a shortened
* string and setting REGEX_MATCH_NOTBOL in the case of a pattern
* that begins with any kind of lookbehind assertion, such as "\\b".
*
* The following example uses g_regex_replace_eval() to replace multiple
* strings at once:
*
* [C example ellipted]
*
* @newin{2,14}
*
* @param string String to perform matches against.
* @param string_len The length of @a string, or -1 if @a string is nul-terminated.
* @param start_position Starting index of the string to match, in bytes.
* @param match_options Options for the match.
* @param eval A function to call for each match.
* @param user_data User data to pass to the function.
* @return A newly allocated string containing the replacements.
*/
Glib::ustring replace_eval(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, GRegexEvalCallback eval, gpointer user_data);
/** Checks whether @a replacement is a valid replacement string
* (see g_regex_replace()), i.e.\ that all escape sequences in
* it are valid.
*
* If @a has_references is not <tt>nullptr</tt> then @a replacement is checked
* for pattern references. For instance, replacement text 'foo\\n'
* does not contain references and may be evaluated without information
* about actual match, but '\\0\\1' (whole match followed by first
* subpattern) requires valid MatchInfo object.
*
* @newin{2,14}
*
* @param replacement The replacement string.
* @param has_references Location to store information about
* references in @a replacement or <tt>nullptr</tt>.
* @return Whether @a replacement is a valid replacement string.
*/
static bool check_replacement(const Glib::ustring& replacement, gboolean* has_references);
};
//TODO: Add C++ iterator like functionality for this class.
/** MatchInfo - MatchInfo is used to retrieve information about the regular
* expression match which created it.
* @newin{2,28}
*/
class MatchInfo
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
using CppObjectType = MatchInfo;
using BaseObjectType = GMatchInfo;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
private:
public:
/// Default constructor.
MatchInfo();
/** C object constructor.
* @param castitem The C object.
* @param take_the_ownership Whether to destroy the C object with the wrapper or
* not.
*/
explicit MatchInfo(GMatchInfo* castitem, bool take_the_ownership = true); //TODO: Rename to take_ownership when we can rename the member variable.
MatchInfo(const MatchInfo& other) = delete;
MatchInfo& operator=(const MatchInfo& other) = delete;
MatchInfo(MatchInfo&& other) noexcept;
MatchInfo& operator=(MatchInfo&& other) noexcept;
/// Destructor.
virtual ~MatchInfo();
/// Provides access to the underlying C object.
GMatchInfo* gobj()
{ return reinterpret_cast<GMatchInfo*>(gobject_); }
/// Provides access to the underlying C object.
const GMatchInfo* gobj() const
{ return reinterpret_cast<GMatchInfo*>(gobject_); }
private:
friend class Regex;
public:
/** Returns Regex object used in @a match_info. It belongs to Glib
* and must not be freed. Use g_regex_ref() if you need to keep it
* after you free @a match_info object.
*
* @newin{2,14}
*
* @return Regex object used in @a match_info.
*/
Glib::RefPtr<Regex> get_regex();
/** Returns Regex object used in @a match_info. It belongs to Glib
* and must not be freed. Use g_regex_ref() if you need to keep it
* after you free @a match_info object.
*
* @newin{2,14}
*
* @return Regex object used in @a match_info.
*/
Glib::RefPtr<const Regex> get_regex() const;
/** Returns the string searched with @a match_info. This is the
* string passed to g_regex_match() or g_regex_replace() so
* you may not free it before calling this function.
*
* @newin{2,14}
*
* @return The string searched with @a match_info.
*/
Glib::ustring get_string() const;
/** Returns whether the previous match operation succeeded.
*
* @newin{2,14}
*
* @return <tt>true</tt> if the previous match operation succeeded,
* <tt>false</tt> otherwise.
*/
bool matches() const;
/** Scans for the next match using the same parameters of the previous
* call to g_regex_match_full() or g_regex_match() that returned
* @a match_info.
*
* The match is done on the string passed to the match function, so you
* cannot free it before calling this function.
*
* @newin{2,14}
*
* @return <tt>true</tt> is the string matched, <tt>false</tt> otherwise.
*/
bool next();
/** Retrieves the number of matched substrings (including substring 0,
* that is the whole matched text), so 1 is returned if the pattern
* has no substrings in it and 0 is returned if the match failed.
*
* If the last match was obtained using the DFA algorithm, that is
* using g_regex_match_all() or g_regex_match_all_full(), the retrieved
* count is not that of the number of capturing parentheses but that of
* the number of matched substrings.
*
* @newin{2,14}
*
* @return Number of matched substrings, or -1 if an error occurred.
*/
int get_match_count() const;
/** Usually if the string passed to g_regex_match*() matches as far as
* it goes, but is too short to match the entire pattern, <tt>false</tt> is
* returned. There are circumstances where it might be helpful to
* distinguish this case from other cases in which there is no match.
*
* Consider, for example, an application where a human is required to
* type in data for a field with specific formatting requirements. An
* example might be a date in the form ddmmmyy, defined by the pattern
* "^\\d?\\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\d\\d$".
* If the application sees the user’s keystrokes one by one, and can
* check that what has been typed so far is potentially valid, it is
* able to raise an error as soon as a mistake is made.
*
* GRegex supports the concept of partial matching by means of the
* REGEX_MATCH_PARTIAL_SOFT and REGEX_MATCH_PARTIAL_HARD flags.
* When they are used, the return code for
* g_regex_match() or g_regex_match_full() is, as usual, <tt>true</tt>
* for a complete match, <tt>false</tt> otherwise. But, when these functions
* return <tt>false</tt>, you can check if the match was partial calling
* g_match_info_is_partial_match().
*
* The difference between REGEX_MATCH_PARTIAL_SOFT and
* REGEX_MATCH_PARTIAL_HARD is that when a partial match is encountered
* with REGEX_MATCH_PARTIAL_SOFT, matching continues to search for a
* possible complete match, while with REGEX_MATCH_PARTIAL_HARD matching
* stops at the partial match.
* When both REGEX_MATCH_PARTIAL_SOFT and REGEX_MATCH_PARTIAL_HARD
* are set, the latter takes precedence.
*
* There were formerly some restrictions on the pattern for partial matching.
* The restrictions no longer apply.
*
* See pcrepartial(3) for more information on partial matching.
*
* @newin{2,14}
*
* @return <tt>true</tt> if the match was partial, <tt>false</tt> otherwise.
*/
bool is_partial_match() const;
/** Returns a new string containing the text in @a string_to_expand with
* references and escape sequences expanded. References refer to the last
* match done with @a string against @a regex and have the same syntax used by
* g_regex_replace().
*
* The @a string_to_expand must be UTF-8 encoded even if REGEX_RAW was
* passed to g_regex_new().
*
* The backreferences are extracted from the string passed to the match
* function, so you cannot call this function after freeing the string.
*
* @a match_info may be <tt>nullptr</tt> in which case @a string_to_expand must not
* contain references. For instance "foo\\n" does not refer to an actual
* pattern and '\\n' merely will be replaced with \\n character,
* while to expand "\\0" (whole match) one needs the result of a match.
* Use g_regex_check_replacement() to find out whether @a string_to_expand
* contains references.
*
* @newin{2,14}
*
* @param string_to_expand The string to expand.
* @return The expanded string, or <tt>nullptr</tt> if an error occurred.
*/
Glib::ustring expand_references(const Glib::ustring& string_to_expand);
/** Retrieves the text matching the @a match_num'th capturing
* parentheses. 0 is the full text of the match, 1 is the first paren
* set, 2 the second, and so on.
*
* If @a match_num is a valid sub pattern but it didn't match anything
* (e.g. sub pattern 1, matching "b" against "(a)?b") then an empty
* string is returned.
*
* If the match was obtained using the DFA algorithm, that is using
* g_regex_match_all() or g_regex_match_all_full(), the retrieved
* string is not that of a set of parentheses but that of a matched
* substring. Substrings are matched in reverse order of length, so
* 0 is the longest match.
*
* The string is fetched from the string passed to the match function,
* so you cannot call this function after freeing the string.
*
* @newin{2,14}
*
* @param match_num Number of the sub expression.
* @return The matched substring, or <tt>nullptr</tt> if an error
* occurred. You have to free the string yourself.
*/
Glib::ustring fetch(int match_num);
/** Retrieves the position in bytes of the @a match_num'th capturing
* parentheses. 0 is the full text of the match, 1 is the first
* paren set, 2 the second, and so on.
*
* If @a match_num is a valid sub pattern but it didn't match anything
* (e.g. sub pattern 1, matching "b" against "(a)?b") then @a start_pos
* and @a end_pos are set to -1 and <tt>true</tt> is returned.
*
* If the match was obtained using the DFA algorithm, that is using
* g_regex_match_all() or g_regex_match_all_full(), the retrieved
* position is not that of a set of parentheses but that of a matched
* substring. Substrings are matched in reverse order of length, so
* 0 is the longest match.
*
* @newin{2,14}
*
* @param match_num Number of the sub expression.
* @param start_pos Pointer to location where to store
* the start position, or <tt>nullptr</tt>.
* @param end_pos Pointer to location where to store
* the end position, or <tt>nullptr</tt>.
* @return <tt>true</tt> if the position was fetched, <tt>false</tt> otherwise. If
* the position cannot be fetched, @a start_pos and @a end_pos are left
* unchanged.
*/
bool fetch_pos(int match_num, int& start_pos, int& end_pos);
/** Retrieves the text matching the capturing parentheses named @a name.
*
* If @a name is a valid sub pattern name but it didn't match anything
* (e.g. sub pattern "X", matching "b" against "(?P<X>a)?b")
* then an empty string is returned.
*
* The string is fetched from the string passed to the match function,
* so you cannot call this function after freeing the string.
*
* @newin{2,14}
*
* @param name Name of the subexpression.
* @return The matched substring, or <tt>nullptr</tt> if an error
* occurred. You have to free the string yourself.
*/
Glib::ustring fetch_named(const Glib::ustring& name);
/** Retrieves the position in bytes of the capturing parentheses named @a name.
*
* If @a name is a valid sub pattern name but it didn't match anything
* (e.g. sub pattern "X", matching "b" against "(?P<X>a)?b")
* then @a start_pos and @a end_pos are set to -1 and <tt>true</tt> is returned.
*
* @newin{2,14}
*
* @param name Name of the subexpression.
* @param start_pos Pointer to location where to store
* the start position, or <tt>nullptr</tt>.
* @param end_pos Pointer to location where to store
* the end position, or <tt>nullptr</tt>.
* @return <tt>true</tt> if the position was fetched, <tt>false</tt> otherwise.
* If the position cannot be fetched, @a start_pos and @a end_pos
* are left unchanged.
*/
bool fetch_named_pos(const Glib::ustring& name, int& start_pos, int& end_pos);
/** Bundles up pointers to each of the matching substrings from a match
* and stores them in an array of gchar pointers. The first element in
* the returned array is the match number 0, i.e. the entire matched
* text.
*
* If a sub pattern didn't match anything (e.g. sub pattern 1, matching
* "b" against "(a)?b") then an empty string is inserted.
*
* If the last match was obtained using the DFA algorithm, that is using
* g_regex_match_all() or g_regex_match_all_full(), the retrieved
* strings are not that matched by sets of parentheses but that of the
* matched substring. Substrings are matched in reverse order of length,
* so the first one is the longest match.
*
* The strings are fetched from the string passed to the match function,
* so you cannot call this function after freeing the string.
*
* @newin{2,14}
*
* @return A <tt>nullptr</tt>-terminated array of gchar *
* pointers. If the previous
* match failed <tt>nullptr</tt> is returned.
*/
Glib::StringArrayHandle fetch_all();
protected:
GMatchInfo* gobject_; // The C object.
bool take_ownership; // Bool signaling ownership. //TODO: Give this a _ suffix when we can break API.
protected:
// So that Glib::Regex::match() can set the C object.
void set_gobject(GMatchInfo* castitem, bool take_ownership = true);
};
} // namespace Glib
namespace Glib
{
/** A Glib::wrap() method for this object.
*
* @param object The C instance.
* @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
* @result A C++ instance that wraps this C instance.
*
* @relates Glib::Regex
*/
Glib::RefPtr<Glib::Regex> wrap(GRegex* object, bool take_copy = false);
} // namespace Glib
#endif /* _GLIBMM_REGEX_H */
|