Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
-mat- filid brandy
firmware
Commits
abf87007
Verified
Commit
abf87007
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
doc: Document MicroPython strings
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
eee6e334
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Documentation/pycardium-guide.rst
+27
-2
27 additions, 2 deletions
Documentation/pycardium-guide.rst
with
27 additions
and
2 deletions
Documentation/pycardium-guide.rst
+
27
−
2
View file @
abf87007
...
@@ -287,9 +287,34 @@ To get really big integers you have to use
...
@@ -287,9 +287,34 @@ To get really big integers you have to use
Strings
Strings
~~~~~~~
~~~~~~~
.. todo::
As in CPython, MicroPython also has multiple string representations: There is
``str``, ``bytes``, and ``bytearray`` but also the above mentions ``QSTR``\ s.
Ideally, code should work with as many of these as possible and to ensure this,
please use these generic functions:
.. code-block:: cpp
#include "py/obj.h"
/* Create a new string object */
char buf[] = "Hello MicroPython!";
mp_obj_t str_obj = mp_obj_new_str(buf, sizeof(buf));
/* Check if an object is a string */
if (mp_obj_is_str(str_obj)) {
/* Either str or QSTR */
}
if (mp_obj_is_str_or_bytes) {
/* Either str, QSTR, or bytes */
}
Strings
/*
* Get a char array from a string object.
* CAUTION! This string is not necessarily null terminated!
*/
char *str_data;
size_t str_len;
str_data = mp_obj_str_get_data(str_obj, &str_len);
Lists & Tuples
Lists & Tuples
~~~~~~~~~~~~~~
~~~~~~~~~~~~~~
...
...
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