Coder Social home page Coder Social logo

wordwrap's Introduction

WordWrap

Go Report Card CI GoDoc

UTF-8 Safe Word Wrapping for Go based on number of bytes.

This is a word wrap library that doesn’t break UTF-8 runes and operates on number of bytes rather than runes. It’s preference is to break on a unicode space character, but will break long words if necessary. This is particularly useful for breaking up unicode messages on protocols where message size is limited by bytes.

Samples

English:

fmt.Println(wordwrap.WrapString(`If any earl, baron, or other person that holds lands directly of the Crown, for military service, shall die, and at his death his heir shall be of full age and owe a 'relief', the heir shall have his inheritance on payment of the ancient scale of 'relief'.`, 60))

Becomes:

If any earl, baron, or other person that holds lands         // 53 bytes
directly of the Crown, for military service, shall die, and  // 60 bytes
at his death his heir shall be of full age and owe a         // 53 bytes
'relief', the heir shall have his inheritance on payment of  // 60 bytes
the ancient scale of 'relief'.                               // 30 bytes

Japanese:

fmt.Println(wordwrap.WrapString(`クラウンの直接土地を保持している任意の伯爵、男爵、または他の人は、兵役のために、死ぬ、と彼の死で彼の後継者は成年であることと「救済」を借りなければならない場合は、相続人は、支払いの彼の継承をもたなければなりません「救済」の古代規模の。`, 60))

Becomes:

クラウンの直接土地を保持している任意の伯  // 60 bytes
爵、男爵、または他の人は、兵役のために、  // 60 bytes
死ぬ、と彼の死で彼の後継者は成年であるこ  // 60 bytes
とと「救済」を借りなければならない場合は  // 60 bytes
、相続人は、支払いの彼の継承をもたなけれ  // 60 bytes
ばなりません「救済」の古代規模の。        // 51 bytes

Korean:

fmt.Println(wordwrap.WrapString(`크라운 의 직접 토지 를 보유하고 있는 백작 , 남작 , 또는 다른 사람이 군 복무 를 위해 죽을 것이요, 그의 죽음 에 그의 후계자 가 전체 연령 하고' 구호 '을 빚을 해야 하는 경우, 상속인 이 지불 에 대한 자신의 상속을 가져야한다 ' 구호 ' 의 고대 규모의 `, 60))

Becomes:

크라운  직접 토지  보유하고 있는 백작  // 59 bytes
, 남작 , 또는 다른 사람이  복무  위해  // 57 bytes
죽을 것이요, 그의 죽음  그의 후계자    // 57 bytes
전체 연령 하고' 구호 '을 빚을 해야 하는    // 55 bytes
경우, 상속인  지불  대한 자신의 상속을 // 60 bytes
가져야한다 ' 구호 '  고대 규모의         // 47 bytes

wordwrap's People

Contributors

dependabot[bot] avatar donatj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wordwrap's Issues

slightly clearer doc ...

I created this because I could not find a library that broke a string by a given number of *bytes* without breaking the *runes* within that string. I needed this to work with a protocol where UTF-8 string message size was limited by bytes.

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.