Esempio n. 1
1
 public function testCopy2()
 {
     $str = CharArray::fromString("Test");
     $str->setSize(5);
     $res = System::arraycopy($str, 1, $str, 2, 3);
     $this->assertEquals("Teest", (string) $res);
 }
Esempio n. 2
0
File: File.php Progetto: phpj/phpj
 public function getParent()
 {
     $path = explode(System::getProperty('file.separator'), $this->path);
     array_pop($path);
     if (empty($path)) {
         return null;
     }
     $path = implode(System::getProperty('file.separator'), $path);
     return new String($path);
 }
Esempio n. 3
0
 public function testCanonicalize()
 {
     $this->assertEquals(System::getProperty("user.dir") . "/composer.json", (string) $this->fs->canonicalize(new String("composer.json")));
 }
Esempio n. 4
0
 public function testGetAbsolutePath()
 {
     $this->assertContains("/", (string) $this->file->getAbsolutePath());
     $this->assertContains("/", (string) $this->file->getCanonicalPath());
     $this->assertContains("/", (string) $this->fileAbs->getAbsolutePath());
     $this->assertContains("/", (string) $this->dir->getAbsolutePath());
     $this->assertContains("/", (string) $this->dirAbs->getAbsolutePath());
     $this->assertContains("/", (string) $this->fileRoot->getAbsolutePath());
     $this->assertContains((string) System::getProperty('user.home'), (string) $this->file->getAbsolutePath());
     $this->assertContains((string) System::getProperty('user.home'), (string) $this->fileAbs->getAbsolutePath());
     $this->assertContains((string) System::getProperty('user.home'), (string) $this->dir->getAbsolutePath());
     $this->assertContains((string) System::getProperty('user.home'), (string) $this->dirAbs->getAbsolutePath());
     $this->assertContains((string) System::getProperty('user.home'), (string) $this->fileRoot->getAbsolutePath());
     $this->assertContains((string) $this->file->getPath(), (string) $this->file->getAbsolutePath());
     $this->assertContains((string) $this->fileAbs->getPath(), (string) $this->fileAbs->getAbsolutePath());
     $this->assertContains((string) $this->dir->getPath(), (string) $this->dir->getAbsolutePath());
     $this->assertContains((string) $this->dirAbs->getPath(), (string) $this->dirAbs->getAbsolutePath());
     $this->assertContains((string) $this->fileRoot->getPath(), (string) $this->fileRoot->getAbsolutePath());
 }
Esempio n. 5
0
 /**
  * @param \PHPJ\Lang\String $prop
  * @param boolean $defaultVal
  * @return bool
  */
 private static function getBooleanProperty(string $prop, $defaultVal = null)
 {
     $val = System::getProperty($prop);
     if ($val === null) {
         return $defaultVal;
     }
     if ($val->equalsIgnoreCase(new String("true"))) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 6
0
File: String.php Progetto: phpj/phpj
 /**
  * Copies characters from this string into the destination character
  * array.
  * <p>
  * The first character to be copied is at index {@code srcBegin};
  * the last character to be copied is at index {@code srcEnd-1}
  * (thus the total number of characters to be copied is
  * {@code srcEnd-srcBegin}). The characters are copied into the
  * subarray of {@code dst} starting at index {@code dstBegin}
  * and ending at index:
  * <blockquote><pre>
  *     dstbegin + (srcEnd-srcBegin) - 1
  * </pre></blockquote>
  *
  * @param      int $srcBegin
  *             index of the first character in the string to copy.
  * @param      int $srcEnd
  *             index after the last character in the string to copy.
  * @param      string $dst
  *             the destination array.
  * @param      int $dstBegin
  *             the start offset in the destination array.
  * @exception StringOutOfBoundsException If any of the following
  *            is true:
  *            <ul><li>{@code srcBegin} is negative.
  *            <li>{@code srcBegin} is greater than {@code srcEnd}
  *            <li>{@code srcEnd} is greater than the length of this
  *                string
  *            <li>{@code dstBegin} is negative
  *            <li>{@code dstBegin+(srcEnd-srcBegin)} is larger than
  *                {@code dst.length}</ul>
  * @return CharArray
  */
 public function getCharsFromTo($srcBegin, $srcEnd, &$dst, $dstBegin)
 {
     $this->validateCharsArguments($srcBegin, $srcEnd, $dst, $dstBegin);
     $dst = $dst instanceof CharArray ? $dst : CharArray::fromString((string) $dst);
     System::arraycopyNoCheck($this->toCharArray(), $srcBegin, $dst, $dstBegin, $srcEnd - $srcBegin);
     return $dst;
 }
Esempio n. 7
0
 /**
  * @param CharArray $str
  * @param int $start
  * @param int $end
  * @return CharArray
  */
 protected function processStrStartEnd(CharArray $str, $start, $end)
 {
     $this->checkSrcBeginEnd($str, $start, $end);
     $len = $end - $start;
     $strCut = new CharArray($len);
     $str = System::arraycopy($str, $start, $strCut, 0, $len);
     return $str;
 }
Esempio n. 8
0
 /**
  * Resolve the given pathname into absolute form.  Invoked by the
  * getAbsolutePath and getCanonicalPath methods in the File class.
  * @param File $f
  * @return \PHPJ\Lang\String
  */
 public function resolveFile(File $f)
 {
     if ($this->isAbsolute($f)) {
         return $f->getPath();
     }
     return $this->resolve(System::getProperty("user.dir"), $f->getPath());
 }