Changeset View
Changeset View
Standalone View
Standalone View
src/utils/PhutilRope.php
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | if ($result === false) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get prefix bytes of the rope, up to some maximum size. | |||||
| * | |||||
| * @param int Maximum number of bytes to read. | |||||
| * @return string Bytes. | |||||
| */ | |||||
| public function getPrefixBytes($length) { | |||||
| $result = array(); | |||||
| $remaining_bytes = $length; | |||||
| foreach ($this->buffers as $buf) { | |||||
| $length = strlen($buf); | |||||
| if ($length <= $remaining_bytes) { | |||||
| $result[] = $buf; | |||||
| $remaining_bytes -= $length; | |||||
| } else { | |||||
| $result[] = substr($buf, 0, $remaining_bytes); | |||||
| $remaining_bytes = 0; | |||||
| } | |||||
| if (!$remaining_bytes) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| return implode('', $result); | |||||
| } | |||||
| /** | |||||
| * Return the entire rope as a normal string. | * Return the entire rope as a normal string. | ||||
| * | * | ||||
| * @return string Normal string. | * @return string Normal string. | ||||
| */ | */ | ||||
| public function getAsString() { | public function getAsString() { | ||||
| return implode('', $this->buffers); | return implode('', $this->buffers); | ||||
| } | } | ||||
| Show All 38 Lines | |||||