Skip to content

Commit

Permalink
Works good for all platforms, stub for JvmNative
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrich committed Oct 27, 2023
1 parent 205a7ba commit 18f4f70
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.junit.Assert._
import org.junit.Test

class ConfigFactoryJvmNativeTests {
// These are in common test but this is File test will be.
@Test def parseString: Unit = {
val configStr =
"""
Expand Down
11 changes: 5 additions & 6 deletions sconfig/shared/src/main/scala/org/ekrich/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,17 @@ import scala.annotation.varargs
* <p> <strong>Serialization</strong>
*
* <p> Convert a `Config` to a JSON or HOCON string by calling [[#root root]] to
* get the [[ConfigObject]] and then call
* [[ConfigValue!.render:String render]] on the root object,
* `myConfig.root.render`. There's also a variant
* get the [[ConfigObject]] and then call [[ConfigValue!.render:String render]]
* on the root object, `myConfig.root.render`. There's also a variant
* [[ConfigValue!.render(options:org\.ekrich\.config\.ConfigRenderOptions)* render(ConfigRenderOptions)]]
* inherited from [[ConfigValue]] which allows you to control the format of the
* rendered string. (See [[ConfigRenderOptions]].) Note that `Config` does not
* remember the formatting of the original file, so if you load, modify, and
* re-save a config file, it will be substantially reformatted.
*
* <p> As an alternative to [[ConfigValue!.render:String render]], the `toString`
* method produces a debug-output-oriented representation (which is not valid
* JSON).
* <p> As an alternative to [[ConfigValue!.render:String render]], the
* `toString` method produces a debug-output-oriented representation (which is
* not valid JSON).
*
* Note: no arg render links do not link correctly. See
* https://github.com/lampepfl/dotty/issues/14212
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package org.ekrich.config

import java.io.{File, Reader}
import java.io.File
import java.net.URL
import java.{util => ju}
import java.util.Properties
Expand Down Expand Up @@ -615,40 +615,6 @@ object ConfigFactory extends PlatformConfigFactory {
def parseProperties(properties: Properties): Config =
parseProperties(properties, ConfigParseOptions.defaults)

/**
* Parses a Reader into a Config instance. Does not call
* [[Config!.resolve()* Config.resolve()]] or merge the parsed stream with any
* other configuration; this method parses a single stream and does nothing
* else. It does process "include" statements in the parsed stream, and may
* end up doing other IO due to those statements.
*
* @param reader
* the reader to parse
* @param options
* parse options to control how the reader is interpreted
* @return
* the parsed configuration
* @throws ConfigException
* on IO or parse errors
*/
def parseReader(reader: Reader, options: ConfigParseOptions): Config =
Parseable.newReader(reader, options).parse().toConfig

/**
* Parses a reader into a Config instance as with
* [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]]
* but always uses the default parse options.
*
* @param reader
* the reader to parse
* @return
* the parsed configuration
* @throws ConfigException
* on IO or parse errors
*/
def parseReader(reader: Reader): Config =
parseReader(reader, ConfigParseOptions.defaults)

/**
* Parses a URL into a Config instance. Does not call
* [[Config!.resolve()* Config.resolve()]] or merge the parsed stream with any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ekrich.config

import java.io.Reader

import org.ekrich.config.impl.Parseable

abstract class ConfigFactoryCommon {
Expand Down Expand Up @@ -29,4 +31,38 @@ abstract class ConfigFactoryCommon {
def parseString(s: String): Config =
parseString(s, ConfigParseOptions.defaults)

/**
* Parses a Reader into a Config instance. Does not call
* [[Config!.resolve()* Config.resolve()]] or merge the parsed stream with any
* other configuration; this method parses a single stream and does nothing
* else. It does process "include" statements in the parsed stream, and may
* end up doing other IO due to those statements.
*
* @param reader
* the reader to parse
* @param options
* parse options to control how the reader is interpreted
* @return
* the parsed configuration
* @throws ConfigException
* on IO or parse errors
*/
def parseReader(reader: Reader, options: ConfigParseOptions): Config =
Parseable.newReader(reader, options).parse().toConfig

/**
* Parses a reader into a Config instance as with
* [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]]
* but always uses the default parse options.
*
* @param reader
* the reader to parse
* @return
* the parsed configuration
* @throws ConfigException
* on IO or parse errors
*/
def parseReader(reader: Reader): Config =
parseReader(reader, ConfigParseOptions.defaults)

}

0 comments on commit 18f4f70

Please sign in to comment.