< prev index next >

src/java.base/share/classes/java/util/regex/Pattern.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


1373 
1374     /**
1375      * Recompile the Pattern instance from a stream.  The original pattern
1376      * string is read in and the object tree is recompiled from it.
1377      */
1378     private void readObject(java.io.ObjectInputStream s)
1379         throws java.io.IOException, ClassNotFoundException {
1380 
1381         // Read in all fields
1382         s.defaultReadObject();
1383 
1384         // reset the flags
1385         flags0 = flags;
1386 
1387         // Initialize counts
1388         capturingGroupCount = 1;
1389         localCount = 0;
1390         localTCNCount = 0;
1391 
1392         // if length > 0, the Pattern is lazily compiled
1393         if (pattern.length() == 0) {
1394             root = new Start(lastAccept);
1395             matchRoot = lastAccept;
1396             compiled = true;
1397         }
1398     }
1399 
1400     /**
1401      * This private constructor is used to create all Patterns. The pattern
1402      * string and match flags are all that is needed to completely describe
1403      * a Pattern. An empty pattern string results in an object tree with
1404      * only a Start node and a LastNode node.
1405      */
1406     private Pattern(String p, int f) {
1407         if ((f & ~ALL_FLAGS) != 0) {
1408             throw new IllegalArgumentException("Unknown flag 0x"
1409                                                + Integer.toHexString(f));
1410         }
1411         pattern = p;
1412         flags = f;
1413 
1414         // to use UNICODE_CASE if UNICODE_CHARACTER_CLASS present
1415         if ((flags & UNICODE_CHARACTER_CLASS) != 0)
1416             flags |= UNICODE_CASE;
1417 
1418         // 'flags' for compiling
1419         flags0 = flags;
1420 
1421         // Reset group index count
1422         capturingGroupCount = 1;
1423         localCount = 0;
1424         localTCNCount = 0;
1425 
1426         if (pattern.length() > 0) {
1427             compile();
1428         } else {
1429             root = new Start(lastAccept);
1430             matchRoot = lastAccept;
1431         }
1432     }
1433 
1434     /**
1435      * The pattern is converted to normalized form ({@link
1436      * java.text.Normalizer.Form#NFC NFC}, canonical decomposition,
1437      * followed by canonical composition for the character class
1438      * part, and {@link java.text.Normalizer.Form#NFD NFD},
1439      * canonical decomposition for the rest), and then a pure
1440      * group is constructed to match canonical equivalences of the
1441      * characters.
1442      */
1443     private static String normalize(String pattern) {
1444         int plen = pattern.length();
1445         StringBuilder pbuf = new StringBuilder(plen);
1446         char last = 0;




1373 
1374     /**
1375      * Recompile the Pattern instance from a stream.  The original pattern
1376      * string is read in and the object tree is recompiled from it.
1377      */
1378     private void readObject(java.io.ObjectInputStream s)
1379         throws java.io.IOException, ClassNotFoundException {
1380 
1381         // Read in all fields
1382         s.defaultReadObject();
1383 
1384         // reset the flags
1385         flags0 = flags;
1386 
1387         // Initialize counts
1388         capturingGroupCount = 1;
1389         localCount = 0;
1390         localTCNCount = 0;
1391 
1392         // if length > 0, the Pattern is lazily compiled
1393         if (pattern.isEmpty()) {
1394             root = new Start(lastAccept);
1395             matchRoot = lastAccept;
1396             compiled = true;
1397         }
1398     }
1399 
1400     /**
1401      * This private constructor is used to create all Patterns. The pattern
1402      * string and match flags are all that is needed to completely describe
1403      * a Pattern. An empty pattern string results in an object tree with
1404      * only a Start node and a LastNode node.
1405      */
1406     private Pattern(String p, int f) {
1407         if ((f & ~ALL_FLAGS) != 0) {
1408             throw new IllegalArgumentException("Unknown flag 0x"
1409                                                + Integer.toHexString(f));
1410         }
1411         pattern = p;
1412         flags = f;
1413 
1414         // to use UNICODE_CASE if UNICODE_CHARACTER_CLASS present
1415         if ((flags & UNICODE_CHARACTER_CLASS) != 0)
1416             flags |= UNICODE_CASE;
1417 
1418         // 'flags' for compiling
1419         flags0 = flags;
1420 
1421         // Reset group index count
1422         capturingGroupCount = 1;
1423         localCount = 0;
1424         localTCNCount = 0;
1425 
1426         if (!pattern.isEmpty()) {
1427             compile();
1428         } else {
1429             root = new Start(lastAccept);
1430             matchRoot = lastAccept;
1431         }
1432     }
1433 
1434     /**
1435      * The pattern is converted to normalized form ({@link
1436      * java.text.Normalizer.Form#NFC NFC}, canonical decomposition,
1437      * followed by canonical composition for the character class
1438      * part, and {@link java.text.Normalizer.Form#NFD NFD},
1439      * canonical decomposition for the rest), and then a pure
1440      * group is constructed to match canonical equivalences of the
1441      * characters.
1442      */
1443     private static String normalize(String pattern) {
1444         int plen = pattern.length();
1445         StringBuilder pbuf = new StringBuilder(plen);
1446         char last = 0;


< prev index next >