Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5978460
TextEdit.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
TextEdit.php
View Options
<?php
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
namespace
Microsoft\PhpParser
;
class
TextEdit
{
/** @var int */
public
$start
;
/** @var int */
public
$length
;
/** @var string */
public
$content
;
public
function
__construct
(
int
$start
,
int
$length
,
string
$content
)
{
$this
->
start
=
$start
;
$this
->
length
=
$length
;
$this
->
content
=
$content
;
}
/**
* Applies array of edits to the document, and returns the resulting text.
* Supplied $edits must not overlap, and be ordered by increasing start position.
*
* Note that after applying edits, the original AST should be invalidated.
*
* @param TextEdit[] $edits
* @param string $text
* @return string
*/
public
static
function
applyEdits
(
array
$edits
,
string
$text
)
:
string
{
$prevEditStart
=
PHP_INT_MAX
;
for
(
$i
=
\count
(
$edits
)
-
1
;
$i
>=
0
;
$i
--)
{
$edit
=
$edits
[
$i
];
\assert
(
$prevEditStart
>
$edit
->
start
&&
$prevEditStart
>
$edit
->
start
+
$edit
->
length
,
"Supplied TextEdit[] must not overlap, and be in increasing start position order."
);
if
(
$edit
->
start
<
0
||
$edit
->
length
<
0
||
$edit
->
start
+
$edit
->
length
>
\strlen
(
$text
))
{
throw
new
\OutOfBoundsException
(
"Applied TextEdit range out of bounds."
);
}
$prevEditStart
=
$edit
->
start
;
$head
=
\substr
(
$text
,
0
,
$edit
->
start
);
$tail
=
\substr
(
$text
,
$edit
->
start
+
$edit
->
length
);
$text
=
$head
.
$edit
->
content
.
$tail
;
}
return
$text
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 20:25 (3 d, 19 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
09/66/83a3d26b519c03b4be0ce0fe92d5
Default Alt Text
TextEdit.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment