{"id":216,"date":"2016-06-14T18:16:15","date_gmt":"2016-06-14T18:16:15","guid":{"rendered":"http:\/\/arnoldvanhofwegen.com\/blog\/?p=216"},"modified":"2016-06-14T14:00:55","modified_gmt":"2016-06-14T14:00:55","slug":"new-red-release-in-sight-a-try-to-help","status":"publish","type":"post","link":"https:\/\/arnoldvanhofwegen.com\/blog\/new-red-release-in-sight-a-try-to-help\/","title":{"rendered":"New Red release in sight! A try to help!"},"content":{"rendered":"<p>A new release of the Red programming language is in the making. Many improvements are added as always.<\/p>\n<p>With this post I will try to push the cart a little on in the right direction.<\/p>\n<p>After I have made ENTAB and DETAB native functions, that wait on publishing to the mainline I wanted to write a blog article about how I did that. But shortly after I saw a similar task on the <a href=\"https:\/\/trello.com\/c\/may3KBGh\/50-natives\" target=\"_blank\">Trello Board<\/a>. The functions ENLINE and DELINE. Seems also pretty straightforward.<\/p>\n<p>What is enline\/deline? Let&#8217;s look at the help.<\/p>\n<p>ENLINE:<br \/>\nR3:<br \/>\n<code>USAGE:<br \/>\nENLINE series<\/code><\/p>\n<p>DESCRIPTION:<br \/>\nConverts string terminators to native OS format, e.g. LF to CRLF.<br \/>\nENLINE is a native value.<\/p>\n<p>ARGUMENTS:<br \/>\nseries &#8212; (modified) (any-string! block!)<\/p>\n<p>R2:<br \/>\n<code>USAGE:<br \/>\nENLINE series \/with end-of-line<\/p>\n<p>DESCRIPTION:<br \/>\nConverts standard string terminators to current OS format, e.g. LF to CRLF. (Modifies)<br \/>\nENLINE is a function value.<\/p>\n<p>ARGUMENTS:<br \/>\nseries -- (Type: any-string block)<\/p>\n<p>REFINEMENTS:<br \/>\n\/with -- Specifies alternate line termination.<br \/>\nend-of-line -- (Type: char string)<br \/>\n<\/code><\/p>\n<p>DELINE:<br \/>\nR3:<br \/>\n<code>USAGE:<br \/>\nDELINE string \/lines<\/p>\n<p>DESCRIPTION:<br \/>\nConverts string terminators to standard format, e.g. CRLF to LF.<br \/>\nDELINE is a native value.<\/p>\n<p>ARGUMENTS:<br \/>\nstring -- (modified) (any-string!)<\/p>\n<p>REFINEMENTS:<br \/>\n\/lines -- Return block of lines (works for LF, CR, CR-LF endings) (no modify)<br \/>\n<\/code><\/p>\n<p>R2:<br \/>\n<code>USAGE:<br \/>\nDELINE string \/lines<\/p>\n<p>DESCRIPTION:<br \/>\nConverts string terminators to standard format, e.g. CRLF to LF. (Modifies)<br \/>\nDELINE is a function value.<\/p>\n<p>ARGUMENTS:<br \/>\nstring -- (Type: any-string)<\/p>\n<p>REFINEMENTS:<br \/>\n\/lines -- Convert to block of lines (does not modify)<br \/>\n<\/code><\/p>\n<p>Does not appear to be too difficult?<br \/>\nEnline:<\/p>\n<ol>\n<li>get the OS, so we know what line terminator we want in the end<\/li>\n<li>replace\/all line terminators to OS-line terminator<\/li>\n<\/ol>\n<p>Deline<\/p>\n<ol>\n<li>get the OS line terminator<\/li>\n<li>change all OS line terminators to standard line terminator.<\/li>\n<\/ol>\n<p>Next step.<\/p>\n<p>Let&#8217;s peek at how it is done in R3 source?<\/p>\n<p>The natives are found <a href=\"https:\/\/github.com\/rebol\/rebol\/blob\/master\/src\/core\/n-strings.c\" target=\"_blank\">here<\/a>.<br \/>\nBut these are more like functions to separate the handling of ASCII and unicode strings, calling other functions in turn.<br \/>\nThe functions that we are really looking for are <a href=\"https:\/\/github.com\/rebol\/rebol\/blob\/master\/src\/core\/s-ops.c\" target=\"_blank\">here<\/a>.<\/p>\n<p>When we look closely we see that the UNI and BYTE functions are practically the same except for the type of characters used.<br \/>\nBecause Red handles these differences internally within the string manipulating functions we will not need two different versions.<\/p>\n<p>Functions in string.reds that are candidate functions we can use<br \/>\n<code><br \/>\nappend-char<br \/>\noverwrite-char<br \/>\ninsert-char<br \/>\nremove-char<br \/>\npoke-char<br \/>\nfind (an action in string.reds)<br \/>\n<\/code><\/p>\n<p>There is also some information in the <a href=\"http:\/\/www.rebol.net\/cookbook\/recipes\/0002.html\" target=\"_blank\">Rebol cookbook<\/a>.<\/p>\n<p>Here we learn the line terminators of OS for free<\/p>\n<ul>\n<li>CR-LF on Windows systems<\/li>\n<li>LF on Unix, Linux, and other Posix systems<\/li>\n<li>CR on Macintosh<\/li>\n<\/ul>\n<p>We sum up the changes deline and enline must make.<br \/>\n<code>deline:<br \/>\nto standard, the lf<br \/>\n- LF -&gt; LF<br \/>\n- CR -&gt; LF<br \/>\n- CR LF -&gt; LF<br \/>\n<\/code><\/p>\n<p>enline:<br \/>\non Windows<br \/>\n<code>- LF -&gt; CR LF<br \/>\n- CR -&gt; CR LF<br \/>\n- CR LF -&gt; CR LF<\/code><\/p>\n<p>on Posix<br \/>\n<code>- LF -&gt; LF<br \/>\n- CR -&gt; LF<br \/>\n- CR LF -&gt; LF<\/code><br \/>\n(This is same as DELINE)<\/p>\n<p>on Mac<br \/>\n<code>- CR -&gt; CR<br \/>\n- LF -&gt; CR<br \/>\n- CR LF -&gt; CR<\/code><br \/>\n(This is same as DELINE but with CR as target)<\/p>\n<p>Perhaps we must do things a little different than Rebol does, improve.<\/p>\n<p>And what about the refinements?<br \/>\nIf I look at it, DELINE should come with a \/with refinement that has a default of lf and it should take cr too.<br \/>\nThe refinement \/lines for DELINE is a troublemaker. Perhaps split is better for such a case?<\/p>\n<p>Is it really needed to support a \/with refinement for ENLINE?<\/p>\n<p>Will you let me know if you like this<br \/>\nTo be continued&#8230; ?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A new release of the Red programming language is in the making. Many improvements are added as always. With this post I will try to push the cart a little on in the right direction. After I have made ENTAB &hellip; <a href=\"https:\/\/arnoldvanhofwegen.com\/blog\/new-red-release-in-sight-a-try-to-help\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts\/216"}],"collection":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":7,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}