259 $this->leader = substr( $string, 0, 24 );
260 $this->fields = array();
261 $this->exceptions = array();
262 $this->raw = $string;
268 $this->
checkString(
"Record Length", $recordLength, $this->leader, 0, 5 );
271 $this->
checkString(
"Base Address of Data", $baseAddressOfData, $this->leader, 12, 5 );
272 $lengthOfLengthOfField = $this->
checkString(
"Length of Length-Of-Field portion of directory entry",
false, $this->leader, 20, 1, $this->defaults[
"lengthOfLengthOfField"] );
273 $lengthOfStartingCharacterPosition = $this->
checkString(
"Length of Starting-Character-Position portion of directory entry",
false, $this->leader, 21, 1, $this->defaults[
"lengthOfStartingCharacterPosition"] );
274 $lengthOfImplementationDefined = $this->
checkString(
"Length of Implementation-Defined portion of directory entry",
false, $this->leader, 22, 1, $this->defaults[
"lengthOfImplementationDefined"] );
275 if(
"$lengthOfLengthOfField$lengthOfStartingCharacterPosition$lengthOfImplementationDefined" !==
"450" ) {
276 $this->
exception(
"MARC21: $lengthOfLengthOfField$lengthOfStartingCharacterPosition$lengthOfImplementationDefined != 450" );
277 $lengthOfLengthOfField = 4;
278 $lengthOfStartingCharacterPosition = 5;
279 $lengthOfImplementationDefined = 0;
285 $lengthOfDirectoryEntry = 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition + $lengthOfImplementationDefined;
287 if( 0 != ( ( $baseAddressOfData-25) % $lengthOfDirectoryEntry ) )
288 $this->
exception(
"ISO2709 4.4.1: Directory does not end on directory entry boundary ".
289 "(Directory is ". ($baseAddressOfData-25).
" bytes long, " .
290 "each entry is 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition + $lengthOfImplementationDefined = $lengthOfDirectoryEntry bytes long, " .
291 "leaving " . (($baseAddressOfData-25)%$lengthOfDirectoryEntry) .
" bytes leftover)" );
296 for( $i = 24 ; $i+$lengthOfDirectoryEntry+1 <= $baseAddressOfData ; $i+= $lengthOfDirectoryEntry ) {
297 $tag = substr( $string, $i, 3 );
299 $off = $this->
checkString(
"Start of field '$tag'",
false, $string, $i+3+$lengthOfLengthOfField, $lengthOfStartingCharacterPosition );
300 if( $baseAddressOfData + $off > strlen($string) ) {
301 $off = substr( $string, $i+3+$lengthOfLengthOfField, $lengthOfStartingCharacterPosition );
302 $this->
exception(
"ISO2709: Offset '$off' of field '$tag' is beyond end of string. Losing this field." );
306 $this->
exception(
"Jack: Data for field '$tag' does not immediately follow a field terminator" );
307 $off = strrpos( substr( $string, 0, $baseAddressOfData + $off ),
ISO2709::FieldTerminator ) - $baseAddressOfData + 1;
310 $imp = substr( $string, $i + 3 + $lengthOfLengthOfField + $lengthOfStartingCharacterPosition, $lengthOfImplementationDefined );
312 $maxFieldLen = intval(
"1" .str_repeat( $lengthOfLengthOfField,
"0" ) ) - 1;
314 while( substr( $string, $i+3, $lengthOfLengthOfField ) ===
"000" ) {
315 $calclen += $maxFieldLen;
316 $i += $lengthOfDirectoryEntry;
317 $newTag = substr( $string, $i, 3 );
318 if( $tag !== $newTag ) {
319 $this->
exception(
"ISO2709 4.4.4: When the recorded field length is 0, each following directory entry refers to the same field. However, we went from '$tag' to '$newTag'.");
320 $i -= $lengthOfDirectoryEntry;
324 $this->
checkString(
"Length of field '$tag'", $len-$calclen, $string, $i+3, $lengthOfLengthOfField );
328 $data = substr( $string, $baseAddressOfData + $off, $len - 1 );
checkString( $name, $trueValue, $string, $start=0, $length=false, $default=false)
AppendFieldBinary( $tag, $data, $directoryEntry=array(), $reorder=false)