File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ final class SequenceMatcher
2727 self ::OP_REP => 'rep ' ,
2828 ];
2929
30+ const OP_STR_TO_INT_MAP = [
31+ 'nop ' => self ::OP_NOP ,
32+ 'eq ' => self ::OP_EQ ,
33+ 'del ' => self ::OP_DEL ,
34+ 'ins ' => self ::OP_INS ,
35+ 'rep ' => self ::OP_REP ,
36+ ];
37+
3038 /**
3139 * @var null|callable either a string or an array containing a callback function to determine if a line is "junk" or not
3240 */
@@ -485,7 +493,7 @@ public function getGroupedOpcodes(int $context = 3): array
485493 }
486494
487495 /**
488- * Convert an operation code into string for human reading .
496+ * Convert an operation code from int into its string form .
489497 *
490498 * @param int $op the operation code
491499 *
@@ -502,6 +510,24 @@ public static function opIntToStr(int $op): string
502510 return self ::OP_INT_TO_STR_MAP [$ op ];
503511 }
504512
513+ /**
514+ * Convert an operation code from string into its int form.
515+ *
516+ * @param string $op the operation code
517+ *
518+ * @throws \InvalidArgumentException
519+ *
520+ * @return int the int representation of the operation code
521+ */
522+ public static function opStrToInt (string $ op ): int
523+ {
524+ if (!isset (self ::OP_STR_TO_INT_MAP [$ op ])) {
525+ throw new \InvalidArgumentException ("Invalid OP: {$ op }" );
526+ }
527+
528+ return self ::OP_STR_TO_INT_MAP [$ op ];
529+ }
530+
505531 /**
506532 * Check if the two lines at the given indexes are different or not.
507533 *
You can’t perform that action at this time.
0 commit comments