All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.strumenta.antlrkotlin.runtime.System.kt Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public object System {
  public interface PrintStream {
    /**
     * Prints the line separator to the standard output stream.
     */
    public fun println()

    /**
     * Prints the given message and the line separator to the standard output stream.
     */
    public fun println(message: String)

    /**
     * Prints the given message to the standard output stream.
     */
    public fun print(message: String)
  }

  public var out: PrintStream = StdPrintStream
  public var err: PrintStream = ErrPrintStream

  public fun getenv(name: String, defaultValue: String? = null): String? =
    platformGetEnv(name) ?: defaultValue

  public fun  arraycopy(src: Array, srcPos: Int, dest: Array, destPos: Int, length: Int) {
    src.copyInto(dest, destPos, srcPos, srcPos + length)
  }

  public fun arraycopy(src: IntArray, srcPos: Int, dest: IntArray, destPos: Int, length: Int) {
    src.copyInto(dest, destPos, srcPos, srcPos + length)
  }

  private object StdPrintStream : PrintStream {
    override fun println(): Unit =
      kotlin.io.println()

    override fun println(message: String): Unit =
      kotlin.io.println(message)

    override fun print(message: String): Unit =
      kotlin.io.print(message)
  }

  private object ErrPrintStream : PrintStream {
    override fun println(): Unit =
      platformPrintErrLn()

    override fun println(message: String): Unit =
      platformPrintErrLn(message)

    override fun print(message: String): Unit =
      platformPrintErr(message)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy