Code Monkey home page Code Monkey logo

strfmt's Introduction

Fork

This repo is a fork of the original strfmt repo by lyro (Frank Fischer) at https://bitbucket.org/lyro/strfmt/.

I do not claim any authorship of this awesome project. I forked it because I am more comfortable with git than mercurial (which is used for the original repo), and I wanted to make this project work once again on Nim devel (2018-06-28).


Introduction

strfmt is a small string formatting library for the Nim programming language similar to Python’s =format=.

Installation

Original

To install the original strfmt, do:

nimble install strfmt

This fork

To install this forked version, do:

nimble install https://github.com/kaushalmodi/strfmt

Documentation

The module is described in this reference documentation.

The documentation is written in Org mode.

  • Pandoc is then used to convert Org to ReStructuredText.
  • nim doc is then used to generate the final HTML documentation that includes the documentation converted from Org and the doc-strings in strfmt.nim.

To generate this documentation locally, do nimble docs. You will find an index.html generated in the docs/ directory.

nimble docs Requirements

  • Pandoc 2.6

Development

To run the tests, clone this repo, cd to the repo directory and run:

nimble test

strfmt's People

Contributors

def- avatar f-fr avatar kaushalmodi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

strfmt's Issues

type mismatch

Using this file:

import strfmt
echo 11.format("3d")
echo "{:3}".fmt(11)

I get this result:

C:\Users\Steven\.nimble\pkgs\strfmt-0.9.1\strfmt.nim(528, 25) Error: type
mismatch: got <tuple of (FmtType, int, int, nil, FmtAlign, FmtSign, bool, bool,
bool, nil)> but expected 'Format = tuple[typ: FmtType, precision: int, width:
int, fill: string, align: FmtAlign, sign: FmtSign, baseprefix: bool, upcase:
bool, comma: bool, arysep: string]'

stringification of floating point numbers is seriously broken

Thanks for your effort to revive this nice library!

Beware that the hand crafted stringification of floating point numbers is seriously broken:

import strfmt

var a = 9.223372036854776e+18

echo "{:f}".fmt(a)

produces this linenoise:

'..--).0-*(+,))+(0(.'..--).0-*(+,))+(0(

strfmt.nim only handles floats somewhat smaller than high(int64). I don't rember at what point the overflow actually occurs.

format separator fails with leading zeros

Using this file:

import strfmt
echo "{:08,}".fmt(1234)

Produces:

0001,234

Compare against JavaScript:

(1234).toLocaleString(0, {minimumIntegerDigits: 7});
"0,001,234"

Python:

>>> format(1234, '08,')
'0,001,234'

Go:

package main
import "golang.org/x/text/language"
import "golang.org/x/text/message"
func main() {
   message.NewPrinter(language.English).Printf("%07d\n", 1234)
   // 0,001,234
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.