Skip to content

Commit

Permalink
Make Bitmap(ppmString:) skip comments in PPM
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriyvan committed May 14, 2024
1 parent 641142f commit 6fac56e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/geometrize/Bitmap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ extension Bitmap {

// Format is described in https://en.wikipedia.org/wiki/Netpbm and https://netpbm.sourceforge.net/doc/ppm.html
public init(ppmString string: String) throws {
let scanner = Scanner(string: string)
var stringWithTrimmedComments = ""
string.enumerateLines { line, _ in
let endIndex = line.firstIndex(of: "#") ?? line.endIndex
stringWithTrimmedComments.append(line[..<endIndex].trimmingCharacters(in: .whitespacesAndNewlines))
stringWithTrimmedComments.append(" ")
}
let scanner = Scanner(string: stringWithTrimmedComments)
scanner.charactersToBeSkipped = .whitespacesAndNewlines
guard scanner.scanString("P3") != nil else {
throw ParsePpmError.noP3
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6fac56e

Please sign in to comment.