Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDE45-Lab3-2019-manfr689-simsc266
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Måns Fredriksson Franzén
TDDE45-Lab3-2019-manfr689-simsc266
Commits
6896b49e
Commit
6896b49e
authored
5 years ago
by
Måns Fredriksson Franzén
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parent
c547fe26
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
copy_file/cpp17.cpp
+1
-0
1 addition, 0 deletions
copy_file/cpp17.cpp
copy_file/win32.c
+13
-0
13 additions, 0 deletions
copy_file/win32.c
part3.cpp
+38
-0
38 additions, 0 deletions
part3.cpp
unicode/unicode.c
+10
-1
10 additions, 1 deletion
unicode/unicode.c
why.txt
+1
-0
1 addition, 0 deletions
why.txt
with
63 additions
and
1 deletion
copy_file/cpp17.cpp
100644 → 100755
+
1
−
0
View file @
6896b49e
...
@@ -12,5 +12,6 @@ int main(int argc, char** argv)
...
@@ -12,5 +12,6 @@ int main(int argc, char** argv)
{
{
assert
(
argc
==
2
);
/* argv[1] is the destination file */
assert
(
argc
==
2
);
/* argv[1] is the destination file */
/* Your code here */
/* Your code here */
filesystem
::
copy
(
L"马Häst马.txt"
,
argv
[
1
]);
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
copy_file/win32.c
+
13
−
0
View file @
6896b49e
...
@@ -5,5 +5,18 @@ int main(int argc, char **argv)
...
@@ -5,5 +5,18 @@ int main(int argc, char **argv)
{
{
assert
(
argc
==
1
);
assert
(
argc
==
1
);
/* Your code here. */
/* Your code here. */
char
*
str
=
"马Häst马.txt"
;
char
*
newfilename
=
"win32.txt"
;
int
wchar_length
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
str
,
-
1
,
NULL
,
0
);
wchar_t
wchar_buffer
[
wchar_length
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
str
,
-
1
,
wchar_buffer
,
wchar_length
);
int
wchar_length2
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
newfilename
,
-
1
,
NULL
,
0
);
wchar_t
wchar_buffer2
[
wchar_length2
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
newfilename
,
-
1
,
wchar_buffer2
,
wchar_length2
);
CopyFileW
(
wchar_buffer
,
wchar_buffer2
,
FALSE
);
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
part3.cpp
0 → 100755
+
38
−
0
View file @
6896b49e
#include
<locale.h>
#include
<string>
#include
<iostream>
#include
<time.h>
using
namespace
std
;
float
foo
(
string
str
);
void
baz
(
float
num
);
i
int
main
()
{
setlocale
(
LC_NUMERIC
,
"sv_SE.UTF8"
);
setlocale
(
LC_ALL
,
"sve_SE.UTF8"
);
string
number
(
"1.2345"
);
string
date
(
"Fri Jul 5 05:04:02 2019"
);
float
svNumber
=
foo
(
number
);
baz
(
svNumber
);
return
0
;
}
float
foo
(
string
str
){
locale
::
global
(
locale
(
"en_US.UTF8"
));
return
stof
(
str
);
}
void
baz
(
float
num
){
locale
::
global
(
locale
(
"sv_SE.UTF8"
));
cout
.
imbue
(
locale
());
cout
<<
num
<<
endl
;
}
This diff is collapsed.
Click to expand it.
unicode/unicode.c
100644 → 100755
+
10
−
1
View file @
6896b49e
...
@@ -15,9 +15,18 @@
...
@@ -15,9 +15,18 @@
*/
*/
FILE
*
my_fopen
(
char
*
str
,
char
*
mode
)
FILE
*
my_fopen
(
char
*
str
,
char
*
mode
)
{
{
#if defined(_MSC_VER) || defined(__MINGW32__)
#if defined(_MSC_VER) || defined(__MINGW32__)
int
wchar_length
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
str
,
-
1
,
NULL
,
0
);
wchar_t
wchar_buffer
[
wchar_length
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
str
,
-
1
,
wchar_buffer
,
wchar_length
);
int
wmode_length
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
mode
,
-
1
,
NULL
,
0
);
wchar_t
wmode_buffer
[
wmode_length
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
mode
,
-
1
,
wmode_buffer
,
wmode_length
);
/* Hint: You want to modify this code */
/* Hint: You want to modify this code */
return
fopen
(
st
r
,
mode
);
return
_w
fopen
(
wchar_buffe
r
,
w
mode
_buffer
);
#else
#else
/* Linux handles UTF-8 by default */
/* Linux handles UTF-8 by default */
return
fopen
(
str
,
mode
);
return
fopen
(
str
,
mode
);
...
...
This diff is collapsed.
Click to expand it.
why.txt
0 → 100755
+
1
−
0
View file @
6896b49e
The filename has symbols from another language in it. These symbols are non-ASCII characters. Therefore we convert to a stream of widechar characters (that are 16-bits wide) instead and print those. The widechar range contain these characters.
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