< prev index next >

src/share/classes/java/util/Scanner.java

Print this page

        

*** 23,42 **** * questions. */ package java.util; - import java.nio.file.Path; - import java.nio.file.Files; - import java.util.regex.*; import java.io.*; import java.math.*; import java.nio.*; import java.nio.channels.*; import java.nio.charset.*; import java.text.*; ! import java.util.Locale; import sun.misc.LRUCache; /** * A simple text scanner which can parse primitive types and strings using --- 23,41 ---- * questions. */ package java.util; import java.io.*; import java.math.*; import java.nio.*; import java.nio.channels.*; import java.nio.charset.*; + import java.nio.file.Path; + import java.nio.file.Files; import java.text.*; ! import java.util.regex.*; import sun.misc.LRUCache; /** * A simple text scanner which can parse primitive types and strings using
*** 993,1004 **** needInput = true; return null; } // Finds the specified pattern in the buffer up to horizon. ! // Returns a match for the specified input pattern. ! private String findPatternInBuffer(Pattern pattern, int horizon) { matchValid = false; matcher.usePattern(pattern); int bufferLimit = buf.limit(); int horizonLimit = -1; int searchLimit = bufferLimit; --- 992,1004 ---- needInput = true; return null; } // Finds the specified pattern in the buffer up to horizon. ! // Returns true if the specified input pattern was matched, ! // and leaves the matcher field with the current match state. ! private boolean findPatternInBuffer(Pattern pattern, int horizon) { matchValid = false; matcher.usePattern(pattern); int bufferLimit = buf.limit(); int horizonLimit = -1; int searchLimit = bufferLimit;
*** 1012,1069 **** if (matcher.hitEnd() && (!sourceClosed)) { // The match may be longer if didn't hit horizon or real end if (searchLimit != horizonLimit) { // Hit an artificial end; try to extend the match needInput = true; ! return null; } // The match could go away depending on what is next if ((searchLimit == horizonLimit) && matcher.requireEnd()) { // Rare case: we hit the end of input and it happens // that it is at the horizon and the end of input is // required for the match. needInput = true; ! return null; } } // Did not hit end, or hit real end, or hit horizon position = matcher.end(); ! return matcher.group(); } if (sourceClosed) ! return null; // If there is no specified horizon, or if we have not searched // to the specified horizon yet, get more input if ((horizon == 0) || (searchLimit != horizonLimit)) needInput = true; ! return null; } ! // Returns a match for the specified input pattern anchored at ! // the current position ! private String matchPatternInBuffer(Pattern pattern) { matchValid = false; matcher.usePattern(pattern); matcher.region(position, buf.limit()); if (matcher.lookingAt()) { if (matcher.hitEnd() && (!sourceClosed)) { // Get more input and try again needInput = true; ! return null; } position = matcher.end(); ! return matcher.group(); } if (sourceClosed) ! return null; // Read more to find pattern needInput = true; ! return null; } // Throws if the scanner is closed private void ensureOpen() { if (closed) --- 1012,1070 ---- if (matcher.hitEnd() && (!sourceClosed)) { // The match may be longer if didn't hit horizon or real end if (searchLimit != horizonLimit) { // Hit an artificial end; try to extend the match needInput = true; ! return false; } // The match could go away depending on what is next if ((searchLimit == horizonLimit) && matcher.requireEnd()) { // Rare case: we hit the end of input and it happens // that it is at the horizon and the end of input is // required for the match. needInput = true; ! return false; } } // Did not hit end, or hit real end, or hit horizon position = matcher.end(); ! return true; } if (sourceClosed) ! return false; // If there is no specified horizon, or if we have not searched // to the specified horizon yet, get more input if ((horizon == 0) || (searchLimit != horizonLimit)) needInput = true; ! return false; } ! // Attempts to match a pattern anchored at the current position. ! // Returns true if the specified input pattern was matched, ! // and leaves the matcher field with the current match state. ! private boolean matchPatternInBuffer(Pattern pattern) { matchValid = false; matcher.usePattern(pattern); matcher.region(position, buf.limit()); if (matcher.lookingAt()) { if (matcher.hitEnd() && (!sourceClosed)) { // Get more input and try again needInput = true; ! return false; } position = matcher.end(); ! return true; } if (sourceClosed) ! return false; // Read more to find pattern needInput = true; ! return false; } // Throws if the scanner is closed private void ensureOpen() { if (closed)
*** 1591,1602 **** clearCaches(); // Expand buffer to include the next newline or end of input int endPosition = 0; saveState(); while (true) { ! String token = findPatternInBuffer(separatorPattern(), 0); ! if (token != null) { endPosition = matcher.start(); break; // up to next newline } if (needInput) { readInput(); --- 1592,1602 ---- clearCaches(); // Expand buffer to include the next newline or end of input int endPosition = 0; saveState(); while (true) { ! if (findPatternInBuffer(separatorPattern(), 0)) { endPosition = matcher.start(); break; // up to next newline } if (needInput) { readInput();
*** 1674,1687 **** throw new IllegalArgumentException("horizon < 0"); clearCaches(); // Search for the pattern while (true) { ! String token = findPatternInBuffer(pattern, horizon); ! if (token != null) { matchValid = true; ! return token; } if (needInput) readInput(); else break; // up to end of input --- 1674,1686 ---- throw new IllegalArgumentException("horizon < 0"); clearCaches(); // Search for the pattern while (true) { ! if (findPatternInBuffer(pattern, horizon)) { matchValid = true; ! return matcher.group(); } if (needInput) readInput(); else break; // up to end of input
*** 1718,1729 **** throw new NullPointerException(); clearCaches(); // Search for the pattern while (true) { ! String token = matchPatternInBuffer(pattern); ! if (token != null) { matchValid = true; position = matcher.end(); return this; } if (needInput) --- 1717,1727 ---- throw new NullPointerException(); clearCaches(); // Search for the pattern while (true) { ! if (matchPatternInBuffer(pattern)) { matchValid = true; position = matcher.end(); return this; } if (needInput)
< prev index next >