| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c48b8f7 commit 3488140
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,6 +125,7 @@ | |||
| 125 | 125 | <Compile Include="nativecall.cs" /> | |
| 126 | 126 | <Compile Include="overload.cs" /> | |
| 127 | 127 | <Compile Include="propertyobject.cs" /> | |
| 128 | + <Compile Include="pyansistring.cs" /> | ||
| 128 | 129 | <Compile Include="pydict.cs" /> | |
| 129 | 130 | <Compile Include="pyfloat.cs" /> | |
| 130 | 131 | <Compile Include="pyint.cs" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,63 @@ | |||
| 1 | + public class PyAnsiString : PySequence { | ||
| 2 | + /// <summary> | ||
| 3 | + /// PyAnsiString Constructor | ||
| 4 | + /// </summary> | ||
| 5 | + /// | ||
| 6 | + /// <remarks> | ||
| 7 | + /// Creates a new PyAnsiString from an existing object reference. Note | ||
| 8 | + /// that the instance assumes ownership of the object reference. | ||
| 9 | + /// The object reference is not checked for type-correctness. | ||
| 10 | + /// </remarks> | ||
| 11 | + | ||
| 12 | + public PyAnsiString(IntPtr ptr) : base(ptr) { } | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + /// <summary> | ||
| 16 | + /// PyString Constructor | ||
| 17 | + /// </summary> | ||
| 18 | + /// | ||
| 19 | + /// <remarks> | ||
| 20 | + /// Copy constructor - obtain a PyAnsiString from a generic PyObject. | ||
| 21 | + /// An ArgumentException will be thrown if the given object is not | ||
| 22 | + /// a Python string object. | ||
| 23 | + /// </remarks> | ||
| 24 | + | ||
| 25 | + public PyAnsiString(PyObject o) | ||
| 26 | + : base() { | ||
| 27 | + if (!IsStringType(o)) { | ||
| 28 | + throw new ArgumentException("object is not a string"); | ||
| 29 | + } | ||
| 30 | + Runtime.Incref(o.obj); | ||
| 31 | + obj = o.obj; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + /// <summary> | ||
| 36 | + /// PyAnsiString Constructor | ||
| 37 | + /// </summary> | ||
| 38 | + /// | ||
| 39 | + /// <remarks> | ||
| 40 | + /// Creates a Python string from a managed string. | ||
| 41 | + /// </remarks> | ||
| 42 | + | ||
| 43 | + public PyAnsiString(string s) | ||
| 44 | + : base() { | ||
| 45 | + obj = Runtime.PyString_FromStringAndSize(s, s.Length); | ||
| 46 | + if (obj == IntPtr.Zero) { | ||
| 47 | + throw new PythonException(); | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + /// <summary> | ||
| 53 | + /// IsStringType Method | ||
| 54 | + /// </summary> | ||
| 55 | + /// | ||
| 56 | + /// <remarks> | ||
| 57 | + /// Returns true if the given object is a Python string. | ||
| 58 | + /// </remarks> | ||
| 59 | + | ||
| 60 | + public static bool IsStringType(PyObject value) { | ||
| 61 | + return Runtime.PyString_Check(value.obj); | ||
| 62 | + } | ||
| 63 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments