Documentation

Comment
in package

JSON comment and trailing comma stripper.

Tags
author

Jitendra Adhikari jiten.adhikary@gmail.com

Table of Contents

$commaPos  : int
$comment  : int
$index  : int
$inStr  : bool
decode()  : mixed
Strip comments and decode JSON string.
parse()  : mixed
Static alias of decode().
parseFromFile()  : mixed
strip()  : string
Strip comments from JSON string.
checkTrail()  : string
doStrip()  : string
getSegments()  : array<string|int, mixed>
hasCommentEnded()  : bool
inCommentEnd()  : bool
inString()  : bool
inStringOrCommentEnd()  : bool
reset()  : mixed

Properties

$commaPos

protected int $commaPos = -1

Holds the backtace position of a possibly trailing comma

$comment

protected int $comment = 0

Lines of comments 0 = no comment, 1 = single line, 2 = multi lines

$index

protected int $index = -1

The current index being scanned

$inStr

protected bool $inStr = false

If current char is within a string

Methods

decode()

Strip comments and decode JSON string.

public decode(string $json[, bool $assoc = false ][, int $depth = 512 ][, int $options = 0 ]) : mixed
Parameters
$json : string
$assoc : bool = false
$depth : int = 512
$options : int = 0
Tags
see
http://php.net/json_decode

[JSON decode native function]

throws
RuntimeException

When decode fails.

Return values
mixed

parse()

Static alias of decode().

public static parse(string $json[, bool $assoc = false ][, int $depth = 512 ][, int $options = 0 ]) : mixed
Parameters
$json : string
$assoc : bool = false
$depth : int = 512
$options : int = 0
Return values
mixed

parseFromFile()

public static parseFromFile(string $file[, bool $assoc = false ][, int $depth = 512 ][, int $options = 0 ]) : mixed
Parameters
$file : string
$assoc : bool = false
$depth : int = 512
$options : int = 0
Return values
mixed

strip()

Strip comments from JSON string.

public strip(string $json) : string
Parameters
$json : string
Return values
string

The comment stripped JSON.

checkTrail()

protected checkTrail(string $char, string $json) : string
Parameters
$char : string
$json : string
Return values
string

doStrip()

protected doStrip(string $json) : string
Parameters
$json : string
Return values
string

getSegments()

protected getSegments(string $json) : array<string|int, mixed>
Parameters
$json : string
Return values
array<string|int, mixed>

hasCommentEnded()

protected hasCommentEnded(string $char, string $next) : bool
Parameters
$char : string
$next : string
Return values
bool

inCommentEnd()

protected inCommentEnd(string $next) : bool
Parameters
$next : string
Return values
bool

inString()

protected inString(string $char, string $prev, string $next) : bool
Parameters
$char : string
$prev : string
$next : string
Return values
bool

inStringOrCommentEnd()

protected inStringOrCommentEnd(string $prev, string $char, string $next) : bool
Parameters
$prev : string
$char : string
$next : string
Return values
bool

reset()

protected reset() : mixed
Return values
mixed

Search results