/
hstring_array.dart
37 lines (32 loc) · 1.02 KB
/
hstring_array.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Extension method to convert HSTRING arrays to List<String>
import 'dart:ffi';
import '../../api_ms_win_core_winrt_string_l1_1_0.dart';
import '../../types.dart';
import '../../utils.dart';
extension HStringHelper on Pointer<HSTRING> {
/// Creates a [List] from `Pointer<HSTRING>`.
///
/// [length] must not be greater than the number of elements stored inside the
/// `Pointer<HSTRING>`.
///
/// ```dart
/// final pHString = ...
/// final list = pHString.toList(length: 5);
/// ```
///
/// {@category winrt}
List<String> toList({int length = 1}) {
final list = <String>[];
for (var i = 0; i < length; i++) {
final element = this[i];
if (element != 0) {
list.add(convertFromHString(this[i]));
WindowsDeleteString(this[i]);
}
}
return list;
}
}