当前位置: 首页>>代码示例>>PHP>>正文


PHP MO::get_byteorder方法代码示例

本文整理汇总了PHP中MO::get_byteorder方法的典型用法代码示例。如果您正苦于以下问题:PHP MO::get_byteorder方法的具体用法?PHP MO::get_byteorder怎么用?PHP MO::get_byteorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MO的用法示例。


在下文中一共展示了MO::get_byteorder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import_from_reader

	function import_from_reader($reader) {
		$reader->setEndian('little');
		$endian = MO::get_byteorder($reader->readint32());
		if (false === $endian) {
			return false;
		}
		$reader->setEndian($endian);

		$revision = $reader->readint32();
		$total = $reader->readint32();
		// get addresses of array of lenghts and offsets for original string and translations
		$originals_lo_addr = $reader->readint32();
		$translations_lo_addr = $reader->readint32();

		$reader->seekto($originals_lo_addr);
		$originals_lo = $reader->readint32array($total * 2); // each of
		$reader->seekto($translations_lo_addr);
		$translations_lo = $reader->readint32array($total * 2);

		$length = create_function('$i', 'return $i * 2 + 1;');
		$offset = create_function('$i', 'return $i * 2 + 2;');

		for ($i = 0; $i < $total; ++$i) {
			$reader->seekto($originals_lo[$offset($i)]);
			$original = $reader->read($originals_lo[$length($i)]);
			$reader->seekto($translations_lo[$offset($i)]);
			$translation = $reader->read($translations_lo[$length($i)]);
			if ('' == $original) {
				$this->set_headers($this->make_headers($translation));
			} else {
				$this->add_entry($this->make_entry($original, $translation));
			}
		}
		return true;
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:35,代码来源:mo.php

示例2: import_from_reader

 /**
  * @param POMO_FileReader $reader
  */
 function import_from_reader($reader)
 {
     $endian_string = MO::get_byteorder($reader->readint32());
     if (false === $endian_string) {
         return false;
     }
     $reader->setEndian($endian_string);
     $endian = 'big' == $endian_string ? 'N' : 'V';
     $header = $reader->read(24);
     if ($reader->strlen($header) != 24) {
         return false;
     }
     // parse header
     $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header);
     if (!is_array($header)) {
         return false;
     }
     // support revision 0 of MO format specs, only
     if ($header['revision'] != 0) {
         return false;
     }
     // seek to data blocks
     $reader->seekto($header['originals_lenghts_addr']);
     // read originals' indices
     $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr'];
     if ($originals_lengths_length != $header['total'] * 8) {
         return false;
     }
     $originals = $reader->read($originals_lengths_length);
     if ($reader->strlen($originals) != $originals_lengths_length) {
         return false;
     }
     // read translations' indices
     $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr'];
     if ($translations_lenghts_length != $header['total'] * 8) {
         return false;
     }
     $translations = $reader->read($translations_lenghts_length);
     if ($reader->strlen($translations) != $translations_lenghts_length) {
         return false;
     }
     // transform raw data into set of indices
     $originals = $reader->str_split($originals, 8);
     $translations = $reader->str_split($translations, 8);
     // skip hash table
     $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4;
     $reader->seekto($strings_addr);
     $strings = $reader->read_all();
     $reader->close();
     for ($i = 0; $i < $header['total']; $i++) {
         $o = unpack("{$endian}length/{$endian}pos", $originals[$i]);
         $t = unpack("{$endian}length/{$endian}pos", $translations[$i]);
         if (!$o || !$t) {
             return false;
         }
         // adjust offset due to reading strings to separate space before
         $o['pos'] -= $strings_addr;
         $t['pos'] -= $strings_addr;
         $original = $reader->substr($strings, $o['pos'], $o['length']);
         $translation = $reader->substr($strings, $t['pos'], $t['length']);
         if ('' === $original) {
             $this->set_headers($this->make_headers($translation));
         } else {
             $entry =& $this->make_entry($original, $translation);
             $this->entries[$entry->key()] =& $entry;
         }
     }
     return true;
 }
开发者ID:cybKIRA,项目名称:roverlink-updated,代码行数:72,代码来源:mo.php

示例3: import_from_reader

	function import_from_reader($reader) {
		$endian_string = MO::get_byteorder($reader->readint32());
		if (false === $endian_string) {
			return false;
		}
		$reader->setEndian($endian_string);

		$endian = ('big' == $endian_string)? 'N' : 'V';

		$header = $reader->read(24);
		if ($reader->strlen($header) != 24)
			return false;

				$header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header);
		if (!is_array($header))
			return false;

		extract( $header );

				if ($revision != 0)
			return false;

				$reader->seekto($originals_lenghts_addr);

				$originals_lengths_length = $translations_lenghts_addr - $originals_lenghts_addr;
		if ( $originals_lengths_length != $total * 8 )
			return false;

		$originals = $reader->read($originals_lengths_length);
		if ( $reader->strlen( $originals ) != $originals_lengths_length )
			return false;

				$translations_lenghts_length = $hash_addr - $translations_lenghts_addr;
		if ( $translations_lenghts_length != $total * 8 )
			return false;

		$translations = $reader->read($translations_lenghts_length);
		if ( $reader->strlen( $translations ) != $translations_lenghts_length )
			return false;

				$originals    = $reader->str_split( $originals, 8 );
		$translations = $reader->str_split( $translations, 8 );

				$strings_addr = $hash_addr + $hash_length * 4;

		$reader->seekto($strings_addr);

		$strings = $reader->read_all();
		$reader->close();

		for ( $i = 0; $i < $total; $i++ ) {
			$o = unpack( "{$endian}length/{$endian}pos", $originals[$i] );
			$t = unpack( "{$endian}length/{$endian}pos", $translations[$i] );
			if ( !$o || !$t ) return false;

						$o['pos'] -= $strings_addr;
			$t['pos'] -= $strings_addr;

			$original    = $reader->substr( $strings, $o['pos'], $o['length'] );
			$translation = $reader->substr( $strings, $t['pos'], $t['length'] );

			if ('' === $original) {
				$this->set_headers($this->make_headers($translation));
			} else {
				$entry = &$this->make_entry($original, $translation);
				$this->entries[$entry->key()] = &$entry;
			}
		}
		return true;
	}
开发者ID:pf5512,项目名称:phpstudy,代码行数:70,代码来源:mo.php


注:本文中的MO::get_byteorder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。