[etoys-dev] Etoys Inbox: Skeleton-Richo.9.mcz

karl ramberg karlramberg at gmail.com
Mon Oct 24 10:06:36 EDT 2011


Way to go :-)

Karl

On Mon, Oct 24, 2011 at 3:44 PM,  <commits at source.squeak.org> wrote:
> Ricardo Moran uploaded a new version of Skeleton to project Etoys Inbox:
> http://source.squeak.org/etoysinbox/Skeleton-Richo.9.mcz
>
> ==================== Summary ====================
>
> Name: Skeleton-Richo.9
> Author: Richo
> Time: 24 October 2011, 10:44:50 am
> UUID: 432931e2-58a1-564e-8603-4f9baa33965f
> Ancestors: Skeleton-Richo.8
>
> Added CSVParser. Since I haven't received a response from Avi Bryant regarding the license of his CSV parser (probably because I don't have his current mail), I decided it would be easy to just made my own.
>
> =============== Diff against Skeleton-Richo.8 ===============
>
> Item was added:
> + SystemOrganization addCategory: #'Skeleton-Base'!
> + SystemOrganization addCategory: #'Skeleton-Base-Sheet'!
> + SystemOrganization addCategory: #'Skeleton-CSV'!
>
> Item was removed:
> - SystemOrganization addCategory: #'Skeleton-Base'!
> - SystemOrganization addCategory: #'Skeleton-Base-Sheet'!
>
> Item was added:
> + Object subclass: #CSVParser
> +       instanceVariableNames: 'stream delimiter'
> +       classVariableNames: ''
> +       poolDictionaries: ''
> +       category: 'Skeleton-CSV'!
>
> Item was added:
> + ----- Method: CSVParser class>>on:delimiter: (in category 'instance creation') -----
> + on: stream delimiter: aCharacter
> +       ^ self basicNew initializeWith: stream delimiter: aCharacter!
>
> Item was added:
> + ----- Method: CSVParser class>>parse: (in category 'parsing') -----
> + parse: aStream
> +       ^ self parse: aStream delimiter: $,!
>
> Item was added:
> + ----- Method: CSVParser class>>parse:delimiter: (in category 'parsing') -----
> + parse: aStream delimiter: aCharacter
> +       ^ (self on: aStream delimiter: aCharacter) parse!
>
> Item was added:
> + ----- Method: CSVParser class>>parseString: (in category 'parsing') -----
> + parseString: aString
> +       ^ self parse: aString readStream !
>
> Item was added:
> + ----- Method: CSVParser class>>parseString:delimiter: (in category 'parsing') -----
> + parseString: aString delimiter: aCharacter
> +       ^ self parse: aString readStream delimiter: aCharacter!
>
> Item was added:
> + ----- Method: CSVParser>>initializeWith:delimiter: (in category 'initialization') -----
> + initializeWith: aStream delimiter: aCharacter
> +       stream := aStream.
> +       delimiter := aCharacter.
> +       self initialize!
>
> Item was added:
> + ----- Method: CSVParser>>nextCell (in category 'parsing') -----
> + nextCell
> +       ^ stream peek = $"
> +               ifTrue: [self nextEnclosedCell]
> +               ifFalse: [self nextNormalCell]!
>
> Item was added:
> + ----- Method: CSVParser>>nextEnclosedCell (in category 'parsing') -----
> + nextEnclosedCell
> +       ^ String streamContents: [:cell |
> +               stream skip: 1.
> +               [stream atEnd]
> +                       whileFalse: [| next |
> +                               next := stream next.
> +                               next = $"
> +                                       ifTrue: [
> +                                               stream peek ~= $"
> +                                                       ifTrue: [^ cell contents]
> +                                                       ifFalse: [stream skip: 1]].
> +                               cell nextPut: next]]!
>
> Item was added:
> + ----- Method: CSVParser>>nextNormalCell (in category 'parsing') -----
> + nextNormalCell
> +       ^ String streamContents: [:cell |
> +               [stream atEnd]
> +                       whileFalse: [| next |
> +                               next := stream next.
> +                               (next = delimiter
> +                               or: [Character cr = next
> +                               or: [Character lf = next]])
> +                                       ifTrue: [stream skip: -1.
> +                                               ^ cell contents].
> +                               cell nextPut: next]]!
>
> Item was added:
> + ----- Method: CSVParser>>nextRow (in category 'parsing') -----
> + nextRow
> +       ^ Array streamContents: [:cells |
> +               [stream atEnd or: [String crlf includes: stream peek]]
> +                       whileFalse: [cells nextPut: self nextCell.
> +                               stream peek = delimiter ifTrue: [stream skip: 1]]]!
>
> Item was added:
> + ----- Method: CSVParser>>parse (in category 'parsing') -----
> + parse
> +       ^ Array streamContents: [:rows |
> +               [stream atEnd]
> +                       whileFalse: [rows nextPut: self nextRow.
> +                               [String crlf includes: stream peek] whileTrue: [stream skip: 1]]]!
>
> Item was changed:
>  ----- Method: Player>>openCSVFile:separator: (in category '*skeleton-data i/o') -----
>  openCSVFile: filePath separator: separator
>        FileStream
>                readOnlyFileNamed: filePath
>                do: [:file || values rows columns |
> +                       values := CSVParser parse: file delimiter: separator.
> -                       values := (CSVParser on: file)
> -                                                       useDelimiter: separator;
> -                                                       rows.
>                        rows := values size.
>                        columns := values first size.
>                        self setTotalRows: rows + 1;
>                                setTotalColumns: columns + 1.
>                        1 to: rows do: [:r|
>                                1 to: columns do: [:c |
>                                        ((values at: r) at: c ifAbsent: nil)
>                                                ifNotNil: [:aString || cell |
>                                                        cell := self sheet assuredCellAt: c @ r.
>                                                        (aString beginsWith: '=')
>                                                                ifTrue: [cell formula: aString]
>                                                                ifFalse: [cell contents: aString]
>                                                        ]]]].!
>
> _______________________________________________
> etoys-dev mailing list
> etoys-dev at squeakland.org
> http://lists.squeakland.org/mailman/listinfo/etoys-dev
>


More information about the etoys-dev mailing list