@@ -306,18 +306,17 @@ static String literalToJavaString(
306306 CharSequence text ,
307307 int start ,
308308 int stop ,
309- boolean isEmptyUnquotedStringOK ,
310- boolean isImpliedStringLiteral ) {
309+ JsonUrlOptions options ) {
311310
312311 if (stop <= start ) {
313- if (isEmptyUnquotedStringOK ) {
312+ if (JsonUrlOptions . isEmptyUnquotedKeyAllowed ( options ) ) {
314313 return EMPTY_STRING ;
315314 }
316315
317316 throw new SyntaxException (MSG_EXPECT_LITERAL , start );
318317 }
319318
320- if (isImpliedStringLiteral ) {
319+ if (JsonUrlOptions . isImpliedStringLiterals ( options ) ) {
321320 return string (buf , text , start , stop , false );
322321 }
323322
@@ -373,18 +372,17 @@ static <V> V literal(
373372 int start ,
374373 int stop ,
375374 ValueFactory <V ,?,?,?,?,?,?,?,?,?> factory ,
376- boolean isEmptyUnquotedStringOK ,
377- boolean isImpliedStringLiteral ) {
375+ JsonUrlOptions options ) {
378376
379377 if (stop <= start ) {
380- if (isEmptyUnquotedStringOK ) {
378+ if (JsonUrlOptions . isEmptyUnquotedValueAllowed ( options ) ) {
381379 return factory .getString ("" );
382380 }
383381
384382 throw new SyntaxException (MSG_EXPECT_LITERAL , start );
385383 }
386384
387- if (isImpliedStringLiteral ) {
385+ if (JsonUrlOptions . isImpliedStringLiterals ( options ) ) {
388386 return factory .getString (
389387 string (buf , text , start , stop , false ));
390388 }
@@ -745,17 +743,15 @@ public static int parseLiteralLength(CharSequence text) {
745743 * @param start start position in text
746744 * @param length number of characters to parse
747745 * @param factory a valid ValueFactory
748- * @param isEmptyUnquotedStringOK if true, allow empty unquoted strings
749- * @param isImpliedStringLiteral if true, assume all literals are strings
746+ * @param options parse options
750747 * @return an object for the parsed literal
751748 */
752749 public static <V > V parseLiteral (
753750 CharSequence text ,
754751 int start ,
755752 int length ,
756753 ValueFactory <V ,?,?,?,?,?,?,?,?,?> factory ,
757- boolean isEmptyUnquotedStringOK ,
758- boolean isImpliedStringLiteral ) {
754+ JsonUrlOptions options ) {
759755
760756 //
761757 // Note: not checking length == 0 here. That case is handled properly
@@ -764,8 +760,9 @@ public static <V> V parseLiteral(
764760
765761 int stop = start + length ;
766762
767- final SyntaxException .Message errmsg = isEmptyUnquotedStringOK
768- ? null : MSG_EXPECT_LITERAL ;
763+ final SyntaxException .Message errmsg =
764+ JsonUrlOptions .isEmptyUnquotedValueAllowed (options )
765+ ? null : MSG_EXPECT_LITERAL ;
769766
770767 parseLiteralLength (text , start , stop , errmsg );
771768
@@ -776,18 +773,17 @@ public static <V> V parseLiteral(
776773 start ,
777774 stop ,
778775 factory ,
779- isEmptyUnquotedStringOK ,
780- isImpliedStringLiteral );
776+ options );
781777 }
782778
783779 /**
784780 * Parse a single literal value.
785781 *
786782 * <p>This simply calls
787- * {@link #parseLiteral(CharSequence, int, int, ValueFactory, boolean, boolean )
783+ * {@link #parseLiteral(CharSequence, int, int, ValueFactory, JsonUrlOptions )
788784 * parseLiteral(s, start, length, JavaValueFactory.PRIMITIVE, false, false)}.
789785 *
790- * @see #parseLiteral(CharSequence, int, int, ValueFactory, boolean, boolean )
786+ * @see #parseLiteral(CharSequence, int, int, ValueFactory, JsonUrlOptions )
791787 * @see JavaValueFactory#PRIMITIVE
792788 */
793789 public static Object parseLiteral (
@@ -800,18 +796,17 @@ public static Object parseLiteral(
800796 start ,
801797 length ,
802798 JavaValueFactory .PRIMITIVE ,
803- false ,
804- false );
799+ null );
805800 }
806801
807802 /**
808803 * Parse a single literal value.
809804 *
810805 * <p>This simply calls
811- * {@link #parseLiteral(CharSequence, int, int, ValueFactory, boolean, boolean )
806+ * {@link #parseLiteral(CharSequence, int, int, ValueFactory, JsonUrlOptions )
812807 * parseLiteral(s, 0, s.length(), JavaValueFactory.PRIMITIVE, false, false)}.
813808 *
814- * @see #parseLiteral(CharSequence, int, int, ValueFactory, boolean, boolean )
809+ * @see #parseLiteral(CharSequence, int, int, ValueFactory, JsonUrlOptions )
815810 * @see JavaValueFactory#PRIMITIVE
816811 */
817812 public static Object parseLiteral (CharSequence text ) {
@@ -820,22 +815,21 @@ public static Object parseLiteral(CharSequence text) {
820815 0 ,
821816 text .length (),
822817 JavaValueFactory .PRIMITIVE ,
823- false ,
824- false );
818+ null );
825819 }
826820
827821 /**
828822 * Parse a single literal value.
829823 *
830824 * <p>This simply calls
831- * {@link #parseLiteral(CharSequence, int, int, ValueFactory, boolean, boolean )
825+ * {@link #parseLiteral(CharSequence, int, int, ValueFactory, JsonUrlOptions )
832826 * parseLiteral(s, 0, s.length(), factory, false, false)}.
833- * @see #parseLiteral(CharSequence, int, int, ValueFactory, boolean, boolean )
827+ * @see #parseLiteral(CharSequence, int, int, ValueFactory, JsonUrlOptions )
834828 */
835829 public static <V > V parseLiteral (
836830 CharSequence text ,
837831 ValueFactory <V ,?,?,?,?,?,?,?,?,?> factory ) {
838- return parseLiteral (text , 0 , text .length (), factory , false , false );
832+ return parseLiteral (text , 0 , text .length (), factory , null );
839833 }
840834
841835 /**
@@ -854,18 +848,21 @@ public static <T extends Appendable> boolean appendLiteral(// NOPMD - Cyclomatic
854848 int start ,
855849 int end ,
856850 boolean isKey ,
857- boolean isEmptyUnquotedStringOK ,
858- boolean isImpliedStringLiteral ) throws IOException {
851+ JsonUrlOptions options ) throws IOException {
859852
860853 if (end <= start ) {
861854 //
862855 // empty string
863856 //
864- if (isEmptyUnquotedStringOK ) {
857+ boolean emptyOK = isKey
858+ ? JsonUrlOptions .isEmptyUnquotedKeyAllowed (options )
859+ : JsonUrlOptions .isEmptyUnquotedValueAllowed (options );
860+
861+ if (emptyOK ) {
865862 return false ;
866863 }
867864
868- if (isImpliedStringLiteral ) {
865+ if (JsonUrlOptions . isImpliedStringLiterals ( options ) ) {
869866 throw new IOException ("implied strings: unexpected empty string" );
870867 }
871868
@@ -876,7 +873,7 @@ public static <T extends Appendable> boolean appendLiteral(// NOPMD - Cyclomatic
876873 return true ;
877874 }
878875
879- if (isImpliedStringLiteral ) {
876+ if (JsonUrlOptions . isImpliedStringLiterals ( options ) ) {
880877 Encode .encode (dest , text , start , end , false , true );
881878 return true ;
882879 }
0 commit comments