Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL_Lockup_Factory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Experience Group
UNL_Lockup_Factory
Commits
24e64d1a
There was a problem fetching the pipeline summary.
Commit
24e64d1a
authored
8 years ago
by
Tyler Lemburg
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests
parent
bb12c6ec
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!4
Update unicode function to allow for ligatures
Pipeline
#
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EasySVG.php
+17
-31
17 additions, 31 deletions
src/EasySVG.php
tests/EasySVGTest.php
+52
-0
52 additions, 0 deletions
tests/EasySVGTest.php
with
69 additions
and
31 deletions
src/EasySVG.php
+
17
−
31
View file @
24e64d1a
...
@@ -91,42 +91,28 @@ class EasySVG {
...
@@ -91,42 +91,28 @@ class EasySVG {
}
}
}
}
$thisValue
=
_ordutf8
(
mb_substr
(
$str
,
$i
,
1
));
$unicode
[]
=
$this
->
_unicodeOrd
(
mb_substr
(
$str
,
$i
,
1
));
if
(
$thisValue
<
128
)
$unicode
[]
=
$thisValue
;
else
{
if
(
count
(
$values
)
==
0
)
$lookingFor
=
(
$thisValue
<
224
)
?
2
:
3
;
$values
[]
=
$thisValue
;
if
(
count
(
$values
)
==
$lookingFor
)
{
$number
=
(
$lookingFor
==
3
)
?
(
(
$values
[
0
]
%
16
)
*
4096
)
+
(
(
$values
[
1
]
%
64
)
*
64
)
+
(
$values
[
2
]
%
64
)
:
(
(
$values
[
0
]
%
32
)
*
64
)
+
(
$values
[
1
]
%
64
);
$unicode
[]
=
$number
;
$values
=
array
();
$lookingFor
=
1
;
}
}
}
}
return
$unicode
;
return
$unicode
;
}
}
private
function
_
ordutf8
(
$string
)
{
private
function
_
unicodeOrd
(
$c
)
{
$k
=
0
;
if
(
ord
(
$c
[
0
])
>=
0
&&
ord
(
$c
[
0
])
<=
127
)
$code
=
ord
(
substr
(
$string
,
$k
,
1
)
);
return
ord
(
$c
[
0
]
);
if
(
$code
>=
128
)
{
//otherwise 0xxxxxxx
if
(
ord
(
$c
[
0
])
>=
192
&&
ord
(
$c
[
0
])
<=
223
)
if
(
$code
<
224
)
$bytesnumber
=
2
;
//110xxxxx
return
(
ord
(
$c
[
0
])
-
192
)
*
64
+
(
ord
(
$c
[
1
])
-
128
);
else
if
(
$code
<
240
)
$bytesnumber
=
3
;
//1110xxxx
if
(
ord
(
$c
[
0
])
>=
224
&&
ord
(
$c
[
0
])
<=
239
)
else
if
(
$code
<
248
)
$bytesnumber
=
4
;
//11110xxx
return
(
ord
(
$c
[
0
])
-
224
)
*
4096
+
(
ord
(
$c
[
1
])
-
128
)
*
64
+
(
ord
(
$c
[
2
])
-
128
);
$codetemp
=
$code
-
192
-
(
$bytesnumber
>
2
?
32
:
0
)
-
(
$bytesnumber
>
3
?
16
:
0
);
if
(
ord
(
$c
[
0
])
>=
240
&&
ord
(
$c
[
0
])
<=
247
)
for
(
$i
=
2
;
$i
<=
$bytesnumber
;
$i
++
)
{
return
(
ord
(
$c
[
0
])
-
240
)
*
262144
+
(
ord
(
$c
[
1
])
-
128
)
*
4096
+
(
ord
(
$c
[
2
])
-
128
)
*
64
+
(
ord
(
$c
[
3
])
-
128
);
$k
++
;
if
(
ord
(
$c
[
0
])
>=
248
&&
ord
(
$c
[
0
])
<=
251
)
$code2
=
ord
(
substr
(
$string
,
$k
,
1
))
-
128
;
//10xxxxxx
return
(
ord
(
$c
[
0
])
-
248
)
*
16777216
+
(
ord
(
$c
[
1
])
-
128
)
*
262144
+
(
ord
(
$c
[
2
])
-
128
)
*
4096
+
(
ord
(
$c
[
3
])
-
128
)
*
64
+
(
ord
(
$c
[
4
])
-
128
);
$codetemp
=
$codetemp
*
64
+
$code2
;
if
(
ord
(
$c
[
0
])
>=
252
&&
ord
(
$c
[
0
])
<=
253
)
}
return
(
ord
(
$c
[
0
])
-
252
)
*
1073741824
+
(
ord
(
$c
[
1
])
-
128
)
*
16777216
+
(
ord
(
$c
[
2
])
-
128
)
*
262144
+
(
ord
(
$c
[
3
])
-
128
)
*
4096
+
(
ord
(
$c
[
4
])
-
128
)
*
64
+
(
ord
(
$c
[
5
])
-
128
);
$code
=
$codetemp
;
if
(
ord
(
$c
[
0
])
>=
254
&&
ord
(
$c
[
0
])
<=
255
)
// error
}
return
FALSE
;
return
$code
;
return
0
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
tests/EasySVGTest.php
0 → 100644
+
52
−
0
View file @
24e64d1a
<?php
class
EasySVGUTF8ToUnicodeTest
extends
\PHPUnit_Framework_TestCase
{
protected
$svg
;
protected
$reflection
;
protected
function
setUp
()
{
$this
->
svg
=
new
EasySVG
;
$this
->
reflection
=
new
\ReflectionClass
(
get_class
(
$this
->
svg
));
}
protected
function
runUTF8Method
(
$string
)
{
$method
=
$this
->
reflection
->
getMethod
(
'_utf8ToUnicode'
);
$method
->
setAccessible
(
true
);
return
$method
->
invokeArgs
(
$this
->
svg
,
array
(
$string
));
}
public
function
testStandardCharacters
()
{
$result
=
$this
->
runUTF8Method
(
'omg lol'
);
$this
->
assertEquals
(
array
(
111
,
109
,
103
,
32
,
108
,
111
,
108
),
$result
);
}
public
function
testStrangeASCII
()
{
$result
=
$this
->
runUTF8Method
(
'ümlaut eñye'
);
$this
->
assertEquals
(
array
(
252
,
109
,
108
,
97
,
117
,
116
,
32
,
101
,
241
,
121
,
101
),
$result
);
}
public
function
testLigatures
()
{
$result
=
$this
->
runUTF8Method
(
'ff fb fj fi fj fk fl ffb ffj ffi ffj ffk ffl fff'
);
$this
->
assertEquals
(
array
(
64256
,
32
,
64261
,
32
,
64263
,
32
,
64257
,
32
,
64263
,
32
,
64264
,
32
,
64258
,
32
,
64265
,
32
,
64267
,
32
,
64259
,
32
,
64267
,
32
,
64268
,
32
,
64260
,
32
,
64256
,
102
),
$result
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment