Giter Site home page Giter Site logo

objoscript's People

Contributors

gkjpettet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

objoscript's Issues

ReadLines Function Fails on Files with multiple EndofLines

Say you have a file containing:

The
quick
brown

fox

jumped

over
the
lazy

dog

When looping thru a readlines generated list, as the code current stands, will render:

The
quick
brown
foxjumpedover
the lazydog

when...

The
quick
brown
fox
jumped
over
the
lazy
dog

is expected.

The changes to the function as below, rectify the issue on all instances containing multiple EndofLines.

Thank you!

`Protected Sub ReadLines(vm As ObjoScript.VM)
/// Returns a list where each item is a line in the file.
///
/// FSItem.readLines() -> List

Var file As ObjoScript.Instance = vm.GetSlotValue(0)

// Error checks.
If file.ForeignData = Nil Or FolderItem(file.ForeignData).Exists = False Then
vm.Error("The file does not exist.")
ElseIf FolderItem(file.ForeignData).IsFolder Then
vm.Error("Cannot read lines from a folder.")
ElseIf Not FolderItem(file.ForeignData).IsReadable Then
vm.Error("Cannot read file.")
End If

Var tin As TextInputStream
tin = TextInputStream.Open(file.ForeignData)

Var lines() As String

try
var tContent as String = tin.ReadAll().ReplaceLineEndings(EndOfLine).ReplaceAll(EndOfLine + EndOfLine, EndOfLine)

While tContent.IndexOf(EndOfLine + EndOfLine) <> - 1
  //recursion
  tContent = tContent.ReplaceAll(EndOfLine + EndOfLine, EndOfLine)
wend

lines = tContent.Split(EndOfLine)

Catch e As RuntimeException
vm.Error("An error occurred whilst reading the file: " + e.Message + ".")
Finally
tin.Close
End Try

vm.SetReturn(vm.NewList(lines))

End Sub`

I wrapped the function with code tags, but GitHub fails to 'code' block the entire function

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.