Settings

The Pnyx library offers three ways to control settings: instance settings, global settings, and settings factory. Each is simple to use and documented below.

Instance

When createing Pnyx objects, a Settings object is created. This object is unique to each Pnyx instance. Changes to these settings only affects the owning instance. Settings can be changed at any state prior to process method. All changes to the Settings object are preformed with the setSettings method. Every parameter to the method is optional so that only the desired settings are affected.

instance:
const String input = "line one\nline two";
using (Pnyx p = new Pnyx())
{
    
    p.setSettings(stdIoDefault: true);    
    p.readString(input);
    p.process(); // automatically writes to STD-OUT
}     
// outputs STD-OUT: 
// line one
// line two

Global

There is a global Settings object, which is Cloned when creating instances of Pnyx. Changes made globally will affect all subsequently created Pnyx objects. The following code shows how to update this global instance.

global:
SettingsHome.settingsFactory = new SettingsHome(
    new Settings
    {
        stdIoDefault = true  // turns on globally
    });

const String input = "line one\nline two";
using (Pnyx p = new Pnyx())
{                
    p.readString(input);
    p.process(); // automatically writes to STD-OUT
}     
// outputs STD-OUT: 
// line one
// line two

Factory

To globally obtain Settings from a file, database or web.config, implement ISettingsFactory. Here is an example:

factory:
        
public class CustomFactory : ISettingsFactory
{
    public Settings buildSettings()
    {
        Settings result = new Settings();
        
        // update from DB, file, web.config, etc
        
        return result;
    }
}

SettingsHome.settingsFactory = new CustomFactory();

using (Pnyx p = new Pnyx())
{
    // uses custom settings
}

Reference

The following lists the settings for Pnyx objects.
tempDirectory: Temporary directory for commands the write to file, like sort and rewrite. Defaults to system's / user's temporary directory.
bufferLines: Buffer size used commands the requiring in-memory buffering, like sort. Defaults to 10,000.
defaultEncoding: Accepts names .net names of encodings, for example: utf-7, utf-8, utf-32, us-ascii. This value is used whenever input files have no BOM markers. Default value is: us-ascii.
outputEncoding: When set, forces the output of all files to use the specified encoding. When not set, the encoding of the input file is used for output. Accepts names .net names of encodings, for example: utf-7, utf-8, utf-32, us-ascii. Values is un-set by default.
detectEncodingFromByteOrderMarks: When true, encoding is read from BOM in input stream. Defaults is true.
outputByteOrderMarks: When true, BOM markers are written to output stream. Default is true.
defaultNewline: One of: Unix, Windows, Native. This value is used whenever input file(s) have no newlines. Default value is: native.
outputNewline: When set, forces the output of all files to use the specified newline. When not set, the newline of the input file is used for output. One of: Unix, Windows, Native. By default, value is un-set.
backupRewrite: When set to true (default), a backup is copied to tempDirectory whenever a file rewrite is used
processOnDispose: When set to true (default), process method is automatically called when Pnyx object is disposed. Otherwise, when set to false, process method must be explicitly called.
stdIoDefault: Defaults to false, however, value is internally overwritten to true when using Pnyx from command line. When true, Pnyx assumes reading from STD-IN and writing to STD-OUT. When false, you must explicitly read and write before compiling / processing Pnyx.

Next

Suggested next steps:
  • Line, learn more about Line operations
  • Row, learn more about Row operations
  • Input, learn more about Input operations
  • Output, learn more about Output operations